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

XML/XSL Help Please! 1

Status
Not open for further replies.

Henk1

Programmer
Oct 26, 2001
46
ZA
Hi,

Sorry for the vague subject, but I don't know the word for what I am looking for.

I have the following XML code:

<?xml version=&quot;1.0&quot;?>
<Report>
<Settings width=&quot;100%&quot;></Settings>
<Heading>
<Title>My Report Title</Title>
<Columns>
<Column id=&quot;A&quot; width=&quot;11%&quot; align=&quot;right&quot; title=&quot;Column-A&quot;/>
<Column id=&quot;B&quot; title=&quot;Column-B&quot;/>
<Column id=&quot;C&quot; title=&quot;Column-C&quot;/>
<Column id=&quot;D&quot; title=&quot;Column-D&quot;/>
<Column id=&quot;E&quot; title=&quot;Column-E&quot;/>
</Columns>
</Heading>
<Data>
<Row> /Report/Heading/Columns/Column(ID)
<Cell column=&quot;A&quot; href=&quot; <Cell column=&quot;B&quot; href=&quot; <Cell column=&quot;C&quot; href=&quot; <Cell column=&quot;D&quot; href=&quot; <Cell column=&quot;E&quot; href=&quot; </Row>
</Data>
<Footer>
<FooterComment>This report is not designed to be printed</FooterComment>
</Footer>
</Report>

I would like to do the following:

<xsl:value-of
select=&quot;/Report/Headings/Columns/Column/@id&quot;/>

The problem is that this will only get the first instance of the @id property. What happens if I want to get the id=&quot;C&quot; or id=&quot;E&quot;. Is there a way of matching a specific value of the id property. I want to be able to read, lets say, the width property of a specific instance of /Report/Heading/Column/Columns, based on the value of id.

If you could help me out, I would appreciate it.
 
in this situation you need to use &quot;[]&quot; to get the result you want.

so the direct answer to your question is /Report/Headings/Columns/Column[@id='A']/@id

i think of the &quot;[]&quot; as meaning &quot;where&quot;. it's probably got some other fancy name :)

you can have more complex XPath with more than one pair of &quot;[]&quot;. the other main thing to know is that to get say the 3rd element you do something like /some/path/to/list/element[3]
 
Hi,

Yes you can do it

Code:
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform&quot;>[/URL]
<xsl:template match=&quot;/&quot;>
testing
<xsl:for-each select=&quot;Report/Heading/Columns/Column[@id = 'A']&quot;>   
<xsl:value-of select=&quot;@width&quot;/> <!--this will output the value of the with attribute-->
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


I hope that this helps

::)
 
Thanks a lot, Mr Tom and Vince,

It worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top