【发布时间】:2015-03-26 00:30:06
【问题描述】:
我正在尝试使用 XSLT 从 docx 的 document.xml 文件中检索目录
这是我的 XSLT:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" exclude-result-prefixes="w" version="2.0">
<xsl:output indent="yes" method="xml"/>
<xsl:strip-space elements="*"/>
<xsl:template match="w:sdt">
<xsl:element name="root">
<xsl:attribute name="label">
<xsl:value-of select="w:sdtPr/w:docPartObj/w:docPartGallery/@w:val"/>
</xsl:attribute>
<xsl:for-each select="w:sdtContent/w:p">
<xsl:if test="w:pPr/w:pStyle/@w:val">
<xsl:element name="sec">
<xsl:attribute name="label">
<xsl:value-of select="w:pPr/w:pStyle/@w:val"/>
</xsl:attribute>
<xsl:attribute name="anchor">
<xsl:value-of select="w:hyperlink/@w:anchor"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="w:hyperlink/w:r/w:t"/>
</xsl:attribute>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:element>
</xsl:if>
</xsl:template>
</xsl:transform>
我得到了想要的结果,但是在 w:sdtContent 范围之外还有额外的 w:p 标签值。
我是 XSLT 的初学者,不知道我在这里做错了什么。
(如果源xml有帮助,请告诉我我会在这里发布。)
【问题讨论】:
-
您的 XSLT 在语法上无效。请先解决这个问题。
标签: xslt docx tableofcontents