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

XSL Translate Function and Multiple Child Nodes 2

Status
Not open for further replies.

werD420

Technical User
Sep 14, 2004
181
US
Hello,
I'm running into an issue when using the translate function on an xpath query. Basically, my xpath statement is only catching elements when they are the first child of a node if i use the translate function

So if this is my xml
Code:
<files>
  <file id="1">
    <tag type="General" text="SAM"/>
  </file>
  <file id="2">
    <tag type="General" text="SAM"/>
    <tag type="General" text="SALLY"/>
  </file>
  <file id="3">
    <tag type="General" text="SALLY"/>
    <tag type="General" text="SAM"/>
  </file>
  <file id="4">
    <tag type="General" text="SAM"/>
  </file>

this xpath gives me files with id 1,2,3,4
Code:
/files/file[tag/@text='SAM']
but this xpath only gives me files with id 1,2,4

Code:
/files/file[translate(tag/@text,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=translate('SAM','ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')]

I'm assuming the problem is with how I'm calling the first translate function with a parameter of "tag/@text" but I don't see a different way of ordering the data that doesn't throw an invalid token error.

Has anyone done this type of child dependent case insensitive xpath statement before?

MCSD, VB.Net <%_%>
 
ok, I had to narrow the translate function down further to the attribute value only

like this
Code:
/files/file[red][tag[/red][translate([blue]@text[/blue],'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=translate('SAM','ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')][red]][/red]

Cheers

MCSD, VB.Net <%_%>
 
This should work:
Code:
files/file/tag[translate(@text,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=translate('SAM','ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')]/..

Tom Morrison
 
Thanks for your response,

That would work.. if i were trying to get a child node of the file's "tag" child node(or just the tag node without your trailing /). But i was seeking to return only the file node as I stated in my original post. My second post covers the solution to my initial question though.

thanks again for posting



MCSD, VB.Net <%_%>
 
ok, i didn't notice the trailing "/.." to step the processor back a node. Thanks for providing an additional solution..

MCSD, VB.Net <%_%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top