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

Branch out or process a node outside of current node

Status
Not open for further replies.

rachelkruzner

Programmer
Jul 31, 2003
2
US
I have the following XML:

<items>
<item number=&quot;100&quot;>
<subitems attr1=..., attr2=....>
<subitem subitemid=&quot;201x&quot;></subitem>
<subitem subitemid=&quot;202x&quot;></subitem>
<subitems>
...
</items>
<orders>
<order number=882, itemnum=&quot;100&quot;, subitemid=&quot;202x&quot;>
<level1>1</level1>
<level1>2</level1>
...
</order>
</orders>

During processing of <orders> element, I'm using an apply-templates to process some data under Items/subitems/subitem element.

apply-templates select=&quot;key('subitem', &quot;100&quot;)/Subitems/Subitem[@subitemid=&quot;202x&quot;]

key is defined as:

<xsl:key name=&quot;subitem&quot; match=&quot;//Items/Item&quot; use=&quot;@number&quot;/>

I expect the apply-templates to only pick up the <subitem> for 202x; however it actually picked up both subitems even though I've specified a matching attribute value.

How can keep the current context in <orders> element and yet able to branch out to process a single node or multiples of a given element somewhere else in the same document?

Thanks in advance
Rachel



 
One of your problems is that you are using double-quotes within double quotes.

&quot;key('subitem', &quot;100&quot;)/Subitems/Subitem[@subitemid=&quot;202x&quot;]

&quot;100&quot; and &quot;202x&quot; should be '100' and '202x'

I haven't looked at your coding in depth, but this is definitely a correction you need to make.
 
Thanks for your reply. Actually, the subitemid value I'm dealing with is 200000000000000028.

<subitems attr1=..., attr2=....>
<subitem subitemid=&quot;200000000000000028&quot;></subitem>
<subitem subitemid=&quot;200000000000000029&quot;></subitem>
<subitems>

When I use apply-templates to access subitem[subitemid='200000000000000028'], it works correctly ie. only one subitem is processed. However, if I use a variable [subitemid=$itemid], then both subitems are being processed. If the values for subitems are alphanumeric, that aalso works fine; only an issue with numbers only.

Anyway, after I put &quot;string&quot; function in front of the the variable, it seems to work fine now.

Thanks again for your input,

Rachel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top