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!

Xpath Issue in external document

Status
Not open for further replies.

Crisps

Programmer
Sep 28, 2006
26
US
I have a an xsl stylesheet that loads a document such as:

<xsl:variable name="sb" select="document('data.xml')/root"/>

the Data xml looks something like

<root>
<function name='Test'>
<data1>data<data1>
</function>
</root>

I would like to address this later in the xsl document by selecting a node such as

<xsl:variable name="function_name" select="$sb/root/function/@name"/>

This always returns nothing. Infact so does $sb/root or $sb/root/function

I can expand the variable in xmlspy when the debugger stops at the location I am trying to use the xpath and it all looks correct. Have you any idea what I am doing wrong?

Note: The XPath doesn't work in the xmlspy debugger watch either.




 
That would be because XPath cannot 'look into' an XSL variable.

So, rather than try to get something to work which will not work, please describe why/how you got to this point. In other words, what problem are you really trying to solve?

Tom Morrison
 
Of course, this will work:
Code:
<xsl:variable name="function_name" select="document('data.xml')/root/function/@name"/>

What's wrong with that?

Tom Morrison
 
Thanks, makes more sense.

Interestingly, $sb/*/*/@name works though. If Xpath cannot look into the variable name, why can it read the specific @name attribute?
 
It will pick up the first function (tacitly and automatically) node under root.

><xsl:variable name="function_name" select="$sb/root/function/@name"/>
[tt]<xsl:variable name="function_name" select="$sb/function/@name"/>[/tt]
 
Okay, I ran this with Stylus Studio. First, correct the two syntax errors in data.xml as follows:
Code:
<root>
    <function name=[COLOR=red]"Test"[/color]>
        <data1>data<[COLOR=red]/[/color]data1>
    </function>
</root>
After doing that, your original formulation ran fine.

I apologize for my misinformation. I went back to my XPath reference and rediscovered how variable references can hold node sets, a fact I have used before (but at my age I forget [blush]).

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top