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

XSLT problem

Status
Not open for further replies.

digitalgerrit

Technical User
Feb 7, 2007
14
NL
Hi there,

I have a simple question. I want to store some info from a certain Tag in an XML file. I want to do this within a for-each loop in an XSLT formatting sheet. I use a variable to do this. The problem is: when I leave the loop the value of the variable is gone. Is there any way to store a value in a general variable throughout the sheet?

Any help will be greatly appreciated, thanks.
 
Your simple question most likely does not have a simple answer. :-(

It may be as simple as declaring the variable at the top level (immediately subordinate to xsl:stylesheet), which will place it in scope for the entire stylesheet. To be any more helpful, I would need to know more detail about what you are trying to accomplish.

Tom Morrison
 
Hi K5tm.

Thanks for the input.
The situation is like this:
I have an XML sheet with many tags, nodes, subnodes and so on. I use XSLT to get some of the information in ASCII, and in one row of ASCII text I have to write some header info and some repeating info from repeating tags. But the header info is not simply gained from the tags higher in the hierarchy, but from some other subtag. In fact, the XML document is not very well designed but I have to deal with it. So this header info will have to be retrieved once and than used throughout the sheet. I am intended tot think in terms of old-fashioned programming concepts like general variables, I shall certainly try your proposed solution of declaring a variable at the top of the sheet.
 
As I understand your approach, you would save something which maps your document in a top-level variable. This would seem to be a reasonable approach.

I would add one caution, however. The context of a top level variable is not in the context of the input document. So be careful about context shifts (e.g. with an xsl:for-each).

Let us know how it works out.

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top