Subject: AW: AW: document() and position() From: "Dirk Holstein" <dirk.holstein@xxxxxxxxxxxxxx> Date: Sat, 22 Jul 2000 17:29:41 +0200 |
Jeni, thank you for the hint. It's the XSLT processor. We have two XSLT processors in use. The first one is the xalan (this is the one I have the problems). The output is: News item 1[2.xml] News item 1[4.xml] The second one is the xt. I've tried the same files on the xt and the output is: News item 1[2.xml] News item 2[4.xml] Is one of the XSLT processors *the best*? We've changed from xt to xalan because of the support. But as it seems it's not the best choice. For this problem I have to do a workaround, because there is no time to change the XSLT processor. But for the future I will know. Thank you very much for your support. sunny greetings from the lake Dirk Holstein -------------------------------------------- web your vision doubleSlash Net-Business GmbH Muellerstr. 12/1 88045 Friedrichshafen Fon 07541 60 47-102 Fax 07541 60 47-111 www.doubleslash.de dirk.holstein@xxxxxxxxxxxxxx > Dirk, > > >If I do anything like this: > > > ><xsl:template match="/"> > > <xsl:apply-templates > select="document(/page/folder)/news[@show = 'true']" > >/> > ></xsl:template> > > > ><xsl:template match="news"> > > <xsl:variable name="index" select="position()" /> > > News item <xsl:value-of select="$index" /> > > ... > ></xsl:template> > > > >I will allways get '1'. Because the 'news' tag is allways the number one > >position in the current xml file. > > I'm very surprised that this is always generating '1'. What XSLT > processor > are you using? When you use the position() function, it should > look at the > position of the current node in the *current node list*, not in the > 'current XML file'. > > Within the template, the current node is the node that's been matched - in > this case the 'news' element. The current node list is set by the > xsl:apply-templates that was used to apply the template. In this > case, the > current node list consists of the nodes specified by the XPath: > > document(/page/folder)/news[@show = 'true'] > > In your example, this list has two nodes in it: the 'news' element from > 2.xml and the 'news' element from 4.xml. So the position() of the first > should be 1 and the position() of the second should be 2. > > I have tested the following files in SAXON and it gives the result that I > think you are after. Please let me know what the resulting output should > look like if I've misinterpreted you. > > ---- test.xml ---- > <?xml version="1.0"?> > <?xml-stylesheet type="text/xsl" href="test.xsl" ?> > <page> > <folder>1.xml</folder> > <folder>2.xml</folder> > <folder>3.xml</folder> > <folder>4.xml</folder> > </page> > ---- > ---- 1.xml ---- > <news show="false"> > 1.xml > </news> > ---- > ---- 2.xml ---- > <news show="true"> > 2.xml > </news> > ---- > ---- 3.xml ---- > <news show="false"> > 3.xml > </news> > ---- > ---- 4.xml ---- > <news show="true"> > 4.xml > </news> > ---- > ---- test.xsl ---- > <?xml version="1.0"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="1.0"> > > <xsl:template match="/"> > <xsl:apply-templates > select="document(/page/folder)/news[@show='true']" /> > </xsl:template> > > <xsl:template match="news"> > News item <xsl:value-of select="position()" />[<xsl:value-of > select="normalize-space(.)" />] > </xsl:template> > > </xsl:stylesheet> > ---- > > Command line: saxon -a -t -o out.xml test.xml > > ---- out.xml ---- > <?xml version="1.0" encoding="utf-8" ?> > News item 1 [2.xml] > > News item 2 [4.xml] > ---- > > I hope this helps, > > Jeni > > Dr Jeni Tennison > Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE > tel: 0115 906 1301 * fax: 0115 906 1304 * email: > jeni.tennison@xxxxxxxxxxxxxxxx > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: AW: document() and position(), Jeni Tennison | Thread | Re: AW: document() and position(), Gary L Peskin |
RE: [ANN] dir to xml command line s, Chris Bayes | Date | RE: checked feature of HTML in XML/, Joshua Allen |
Month |