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!

Querry tags by XSL problem!! Help me pls!!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Help me!!!
How can I querry tags that their attribute contains any string (that I need) from a XML file using XSLT??
ex:
<TESTS>
<TEST ID=&quot;1&quot; NAME=&quot;aaa&quot;/>
<TEST ID=&quot;2&quot; NAME=&quot;baa&quot;/>
<TEST ID=&quot;3&quot; NAME=&quot;aac&quot;/>
<TEST ID=&quot;4&quot; NAME=&quot;bbb&quot;/>k
</TESTS>

How can I get all <TEST> that have string &quot;aa&quot; in their attribute @NAME ??? ( The right result is the <TEST>s that have ID= 1, 2, 3)
Help me please.
Thank U very much! :))
 
An example:

My xml is like:

<e2contacts>
<company>
<coname>ABC Limited<coname>
.
.
<contacts>
<surname>Smith</
.
.
</contacts>
<contacts>
<surname>Brown</
.
.
</contacts>
</company>
<company> etc etc etc

My XSL:

<xsl:template match=&quot;e2contacts&quot;>
<xsl:apply-templates select=&quot;company&quot; mode=&quot;toc&quot;/>
</xsl:template>

<xsl:template match=&quot;company[[contacts[contains(surname,'arr')]]&quot; mode=&quot;toc&quot;>
<xsl:value-of select=&quot;coname&quot;/>
</xsl:template>

This selcts all company bits that have a contact who has a surname containing the string arr. Unfortunately you cannot use regular expressions or wild cards so a*c will not find abc acc - it will simply fail to do anything.

The secret is the nested tests in square brackets if the test is more than one level down. In your example of course you need the attribute symbol @ before the attribute name and possibly the simpler form:

<xsl:template match=&quot;TEST[contains(@ID,'arr')]&quot; mode=&quot;toc&quot;>


Just a thought - have you had any luck setting variables to the value of an element? This one baffles me.


Hope this helps
Nigel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top