Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying xpath through xslt

Status
Not open for further replies.

gurugunjaal

Programmer
Joined
Dec 4, 2003
Messages
1
Location
US
I nedd to display all the xpaths of an xml using a xslt how can i do that. The xslt should be generic enough to generate all xpaths.
<root>
<a>
<b>
<c> blahh</c>
</b>
</a>
<x>....
Out put ascii file should have two columns 1 xpath 2. content as follows
root/a/b/c blah
root/x/y/z blahh..
etc
How can I do this using xslt.. I am using java parser to do xslt transformation..
Please help me
Thanks in advance


 
Something like:
Code:
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform&quot;>[/URL]
  <xsl:output encoding=&quot;UTF-8&quot; indent=&quot;yes&quot; method=&quot;text&quot; version=&quot;1.0&quot;/>

  <xsl:template match=&quot;/&quot;>
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match=&quot;*&quot;>
    <xsl:call-template name=&quot;printsubs&quot;>
      <xsl:with-param name=&quot;xpath&quot; select=&quot;name()&quot;/>
    </xsl:call-template>
  </xsl:template>
  
  <xsl:template name=&quot;printsubs&quot;>
    <xsl:param name=&quot;xpath&quot;/>
    <xsl:choose>
      <xsl:when test=&quot;count(*)!=0&quot;>
        <xsl:for-each select=&quot;*&quot;>
          <xsl:call-template name=&quot;printsubs&quot;>
            <xsl:with-param name=&quot;xpath&quot; select=&quot;concat($xpath,'/',name())&quot;/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select=&quot;$xpath&quot;/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select=&quot;.&quot;/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top