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

Document() 1

Status
Not open for further replies.

JontyMC

Programmer
Nov 26, 2001
1,276
0
0
GB
When you use document() in a for-each, how do you refer to the original document?

Code:
<xsl:for-each select="document('mydoc.xml')">
  <xsl:value-of select="????"/>
</xsl:for-each>
 
Any ideas? I really need to refer to the original context document of the stylesheet within the for-each.
 
hmm why not refer to document in a variable?
Code:
<xsl:variable name="myextdoc">
<xsl:copy-of select="document('mydoc.xml')"/>
</xsl:variable>

....

<xsl:for-each select="$myextdoc/*"/>
<xsl:value-of select="internal-node/*[local-name()=./text()"/>
</xsl:for-each>

...

however i'm still looking for a better solution, i know u dont like using variables ;)

matt

 
Haha. Yes, I'd rather not use variables if possible.

I thought document('') would work, but that gives you the root of the actual stylesheet.

I want to do something like document(..) or document(previous-document). I'm sure it must be possible.
 
hmmm just had another thought.. don't know how efficient it is but assuming the current input document is called "myinput.xml" and the other xml doc is called "theother.xml" you could do this:

Code:
<xsl:for-each select="document('theother.xml')/*">
<xsl:value-of select="document('myinput.xml')/*[local-name()=./text()"/>
</xsl:for-each>

again as i say, it's probably not that efficient.

matt

 
Thanks for the efforts matt. After reading posts off that forum I think I'll have to give up the ghost and use a variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top