A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Spring in Action
this week in the
XML and Related Technologies
XSL: cycle every element
Joined: Jul 01, 2011
Nov 08, 2011 01:16:17
I need to verify if any element of an XML file contains an attribute called "id"; for example:
<person> <name> Bob </name> <city id="5"> London </city> </person>
And this is what I wrote but it seems not working
<xsl:for-each select="$xmlFile/node()" > <xsl:variable name="currentNode" select="current()"/> <xsl:choose> <xsl:when test="$currentNode/@id"> <xsl:message>ID ok for element <xsl:value-of select="$currentNode" /> </xsl:message> </xsl:when> <xsl:otherwise> <xsl:message>No ID for element <xsl:value-of select="$currentNode" /> </xsl:message> </xsl:otherwise> </xsl:choose> </xsl:for-each>
When I print $currentNode I would like to get printed the name of the node.
Joined: Oct 14, 2005
Nov 08, 2011 09:36:53
I don't know what that "$xmlfile" variable might be, but you are only looking at its children in that code, not all of its descendants.
Why don't you just write an XPath expression which selects all nodes with an "id" attribute? That would be far easier than writing your own code to search the document.
Joined: Jan 18, 2011
Nov 10, 2011 09:25:50
Instead of this:
I agree. Here's the link:
subject: XSL: cycle every element
XSLT Stylesheet test for special character
Newbie problem with XSLT
XSLT merging help
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014