【发布时间】:2016-01-07 11:45:46
【问题描述】:
对于关于 xsl:template 和命名空间的第一百个问题,我深表歉意。我确实阅读了其他问题(例如 here、here 和 here),但仍然无法将这些问题拼凑在一起。
这是我的输入:
<?xml version="1.0" encoding="UTF-8" ?>
<AuthorIT version="6.2.0" xmlns="http://www.authorit.com/xml/authorit"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.authorit.com/xml/authorit AuthorIT.xsd">
<Objects>
<Book>
<Object>
<Description>1089-802-01</Description>
</Object>
</Book>
</Objects>
</AuthorIT>
这是我的样式表:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ait="http://www.authorit.com/xml/authorit" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.authorit.com/xml/authorit AuthorIT.xsd">
<xsl:template match="/">
<Table>
<apply-templates/>
</Table>
</xsl:template>
<xsl:template match="ait:Book">
<Row>
<Cell>
<Data><xsl:value-of select="./Object/Description"/></Data>
</Cell>
</Row>
</xsl:template>
预期结果:
<Table>
<Row>
<Cell>
<Data>1089-802-01</Data>
</Cell>
</Row>
</Table>
实际结果:
<Table>
1089-802-01
</Table>
换句话说,xsl:template match="/" 匹配,但 xsl:template match="ait:Book" 不匹配。
如何匹配 Book 元素?
请注意,我从输入根元素 AuthorIT xmlns="http://www.authorit.com/xml/authorit" 中获取了默认命名空间,并将其作为 添加到样式表中xmlns:ait="http://www.authorit.com/xml/authorit"。 然后我尝试将 Book 元素匹配为 ait:Book。但我一定误会了this answer。
我不知道它是否重要,但我正在使用 Saxon HE 9 和 Notepad++ XML 插件。
【问题讨论】:
标签: xml xslt namespaces