【发布时间】:2014-03-12 11:29:54
【问题描述】:
考虑以下 XML:
<mergeddocx>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<w:hyperlink r:id="rId9">
<w:r>
<w:t>Hello World!!</w:t>
</w:r>
</w:hyperlink>
</w:document>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId9" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="http://x1y1z1.com/" TargetMode="External" />
</Relationships>
</mergeddocx>
当我尝试使用以下 XSL 脚本解析它时:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
exclude-result-prefixes="w r">
<xsl:template match="w:hyperlink">
<a>
<xsl:variable name="rId">
<xsl:value-of select="@r:id"/>
</xsl:variable>
<xsl:if test="/mergeddocx/Relationships">
<xsl:attribute name="href">
<xsl:value-of select="$rId"/>
</xsl:attribute>
</xsl:if>
<xsl:attribute name="target">
<xsl:text>_blank</xsl:text>
</xsl:attribute>
</a>
</xsl:template>
而不是得到预期的输出:
<a href="rId9" target="_blank">
</a>
我得到的是:
<a target="_blank"/>
xsl:if 中的 xpath 不接受 mergeddocx 标记内有 Relationships 标记。但是,当我在测试 xpath 中仅使用 /mergeddocx 时,它可以正常工作。
我在这里做错了什么?如何在我的 xpath 中包含包含非命名空间的标签?
提前谢谢!!
【问题讨论】:
标签: xml xslt xpath xslt-1.0 openxml