I am trying to retrieve the TOC from docx's document.xml file using XSLT
Here is my 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>
i am getting the desired result but with additional w:p tag values outside of w:sdtContent scope.
I am a beginner in XSLT and not sure what i am doing wrong here.
(if the source xml would help, please let me know i will post it here.)