Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 19th, 2008, 09:54 AM
Authorized User
 
Join Date: May 2007
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting node’s name

Hi. Guys
I have an xml doc like the one below. I wonder how to read the name of each node in the xml doc. i.e. p1, p2 and p3 then store them into variables. Is it possible to do this using XSLT. How?

Your help is much appreciated

Cheers

<login>

    <p1 id="x" password="y" />


    <p2 id="xx" password="yy" />


    <p3 id="xxx" password="yyy" />


</login>


 
Old February 19th, 2008, 10:14 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Here is a sample XSLT 1.0 stylesheet that uses the local-name function to output the local name of all element nodes:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:for-each select="//*">
      <xsl:value-of select="concat(local-name(), '#13;#10;')"/>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>
 
Old February 19th, 2008, 10:21 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I find your use of the phrase "store them in variables" interesting.

Could you explain exactly why you want to store these in variables (and what type of variables? XSLT variables? Java variables?) and what you want to do with the variables.

I suspect there is a better way of doing what you are trying to do.

/- Sam Judson : Wrox Technical Editor -/









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.