Re: determining position of a document included using
Gennady Loskutov wrote: > I use generate-id() function to identify the included file. > Basically, the idea is to match generated id for the root element of > the current node with ones, generated separately and stored in a > variable. According to XSLT spec, > generate-id(document("foo.xml"))=generate-id(document("foo.xml")) is > always true, so I assume that > generate-id(document("foo.xml"))=generate-id(document(/files/file/@href)) > must be also true if the "foo.xml" file is among those specified in > /files/file/@href. > > To use my solution, you must use an extension function to transform > a result tree fragment stored in a variable into a node set (I use > Microsoft XML parser, which has node-set() function). That's a really good idea. I don't think that you need to use the node-set() extension function to implement it, though... You can store all the file elements in a global variable: <xsl:variable name="files" select="/files/file" /> Then within the template that's processing one of the nodes in the document that the file element references, you can first generate the ID of the root node for that document: <xsl:variable name="doc" select="generate-id(/)" /> And then look at all the file elements (stored in that global variable) to find the one where, when you retrieve the document associated with its href attribute and generate an ID for it, you get the same generated ID as the one stored in $doc: <xsl:variable name="file" select="$files[generate-id(document(@href)) = $doc]" /> And then you can count how many preceding sibling file elements it has to work out its position: <xsl:variable name="position" select="count($file/preceding-sibling::file) + 1" /> Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format