I'm trying to apply transformation to xml so that the output is the xpath of all the child elements. so for example:
<envelope>
<body>
<result>
<Testimonial>
<directional>
<allowed ><?xml version="1.0" encoding="utf-8"?> hi john <how is it></allowed>
<test><hi></test>
<test><hi></test>
</directional>
<directional>
<allowed ><?xml version="1.0" encoding="utf-8"?> hi john <how is it></allowed>
<test><hi></test>
</directional>
</Testimonial>
</result>
</body>
</envelope>
should be transformed into:
/envelope[1]/body[1]/result[1]/Testimonial[1]/directional[1]/allowed[1]
/envelope[1]/body[1]/result[1]/Testimonial[1]/directional[1]/test[1]
/envelope[1]/body[1]/result[1]/Testimonial[1]/directional[1]/test[2]
/envelope[1]/body[1]/result[1]/Testimonial[1]/directional[2]/allowed[1]
/envelope[1]/body[1]/result[1]/Testimonial[1]/directional[2]/test[1]
Below is my XSLT, the problem i have is that i cannot get it to target child elements only. In current form below the parents are also included in output which isn't what i want.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" media-type="text/plain"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*|@*">
<xsl:param name="path" select="''"/>
<xsl:variable name="this-path">
<xsl:value-of select="concat($path, '/')"/>
<xsl:if test="../@*[name() = name(current())]">
<xsl:text>@</xsl:text>
</xsl:if>
<xsl:value-of select="name()"/>
<xsl:if test="count(../*[name() = name(current())]) > 1">
<xsl:value-of select="concat('[', count(preceding-sibling::*[name()
= name(current())]) + 1, ']')"/>
</xsl:if>
<xsl:if test="count(../*[name() = name(current())]) <= 1">
<xsl:value-of select="'[1]'"/>
</xsl:if>
</xsl:variable>
<xsl:if test="preceding::*|ancestor::*">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="$this-path"/>
<xsl:apply-templates select="*|@*">
<xsl:with-param name="path" select="$this-path"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="comment()|text()|processing-instruction()"/>
</xsl:stylesheet>
How can i make the output to be the xpaths of just the child elements?