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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting attributes wityh xsl

Status
Not open for further replies.

newbie404

Programmer
Mar 2, 2004
19
IE
Hi.
I am writing some xsl to extract attribute details from an xml file and display them.
My problem is I am not getting the output!

The xsl (a section of it) is -

<xsl:for-each select="Option[@correctanswer='true']">
<div id="filename">
<xsl:value-of select="@id" />
</div>
</xsl:for-each>


The xml (a section of it) is -

<Option correctanswer="true" id="Option15">
</Option>



What I expect is to see the attribut, but I do not. Any idea what could cause this?
 
try this

<xsl:for-each select="Option[@correctanswer='true']">
<div id="filename">
<xsl:value-of select="Option/@id" />
</div>
</xsl:for-each>
 
Here is a working example which may help

Code:
<?xml version='1.0'?>
<Options>
<Option correctanswer="true" id="Option15"></Option>
<Option correctanswer="false" id="Option16"></Option>
<Option correctanswer="true" id="Option17"></Option>
</Options>


Code:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL]
                version="1.0">

<xsl:template match="/">
      <xsl:apply-templates select="//Option[@correctanswer='true']"/>
</xsl:template>

<xsl:template match="Option" > 
    <div id="filename">
    <xsl:value-of select="@id" /> 
    </div>
</xsl:template>

</xsl:stylesheet>

As you can see, you may not need to use a for loop.

- F
 
Thanks for the two suggestions, but I still can't get it to work. Totally stumped with this one. Any other suggestions are more than welcome.

thanks
Andy
 
Post the full xml and xsl files. Without more
details I doubt if anyone can help you.
 
Thanks for all the help - I got it working with

<xsl:value-of select="./@id" />
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top