DXL 的 XSLT 转换不起作用

XSLT transformation of DXL not working

我有以下 DXL(即 Lotus Notes XML 数据):

<?xml version='1.0' encoding="ISO-8859-1"?>
<document xmlns='http://www.lotus.com/dxl' version='6.5' maintenanceversion='4.0'>
    <noteinfo>
        <created><datetime>20020225T160055,64-05</datetime></created>
    <updatedby><name>CN=John Doe/O=MyOrg</name></updatedby>
    </noteinfo>
 </document>

我正在尝试使用 XSLT 样式表将 DXL 转换为 HTML,但生成的 HTML 不包含任何数据元素。我以前没有使用过 DXL 数据,而且我的 XSLT 有点生疏,所以我不确定是什么问题。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
    <xsl:template match="/">
        <html>
            <body>
                <h2>Submission</h2>
                <table border="1">
                        <tr>
                            <td>Create date:</td>
                            <td><xsl:value-of select="document/noteinfo[1]/created[1]/datetime[1]"/></td>
                        </tr>
                        <tr>
                            <td>Updated by:</td>
                            <td><xsl:value-of select="updatedby[1]/name[1]"/></td>
                        </tr>             
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

您的来源 XML 中声明了一个默认命名空间:

<document xmlns='http://www.lotus.com/dxl' version='6.5' maintenanceversion='4.0'>

这意味着您需要声明它并在样式表中的 XPath 中使用它:

   <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:my="http://www.lotus.com/dxl">

然后您需要在 XSLT 中的 XPath 中引用它:

<xsl:value-of select="my:document/my:noteinfo[1]/my:created[1]/my:datetime[1]"/>

如果您使用 XSLT 2.0,您可以在样式表部分指定 xpath-default-namespace="http://www.lotus.com/dxl"

这是我的尝试,使用命名空间声明:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0" xmlns:my="http://www.lotus.com/dxl">
    <xsl:template match="/">
        <html>
            <body>
                <h2>Submission</h2>
                <table border="1">
                        <tr>
                            <td>Create date:</td>
                            <td><xsl:value-of select="my:document/my:noteinfo[1]/my:created[1]/my:datetime[1]"/></td>
                        </tr>
                        <tr>
                            <td>Updated by:</td>
                            <td><xsl:value-of select="my:document/my:noteinfo[1]/my:updatedby[1]/my:name[1]"/></td>
                        </tr>             
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

您的 Updated by 单元格的 XPath 不正确,因此我对此进行了自己的更正以从您的示例 XML.

中获取值