Question on XSL expression Got this XML: <Body> <Page> <Line no="9" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line> <Line no="10" detail="true"> <onefield>onefieldstext</onefield> <fgman9>fgmanfieldstext</fgman9> <twofield>twofieldstext</twofield> </Line> <Line no="11" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line> <Line no="12" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line> <Line no="13" detail="true"> <onefield>onefieldstext</onefield> <fgman5>fgmanfieldstext</fgman5> <twofield>twofieldstext</twofield> </Line> <Line no="14" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line> </Page> </Body> I would select the <Line/> nodes without text-node children whose names is starting with "fgman" - in this example it is all <Line/> _except_ <fgman9/> and <fgman5/> in <Line/> with @no of 10 and 13. I know that this works: <xsl:for-each select="Body/Page/Line[@detail]"> <xsl:if test="count(fgman9|fgman5) = 0"> L<xsl:value-of select="@no"/>:<xsl:value-of select="onefield"/> </xsl:if> <xsl:if test="fgman9"> <xsl:value-of select="@no"/> Ouuch</xsl:if> <xsl:if test="fgman5"> <xsl:value-of select="@no"/> Whoops</xsl:if> </xsl:foreach> But as the <fgmanXXX/> nodes could be named fgman0 to fgman1000 I would prefer not to list everyone as arguments to the count() expression. /Reiche
Michael Reiche wrote: > I know that this works: > > <xsl:for-each select="Body/Page/Line[@detail]"> > > <xsl:if test="count(fgman9|fgman5) = 0"> > L<xsl:value-of select="@no"/>:<xsl:value-of select="onefield"/> > </xsl:if> > > <xsl:if test="fgman9"> > <xsl:value-of select="@no"/> Ouuch</xsl:if> > > <xsl:if test="fgman5"> > <xsl:value-of select="@no"/> Whoops</xsl:if> > > </xsl:foreach> > within a xsl:choose instruction you could filter out all elements having unwanted children using starts-with(), eg: <xsl:choose> <xsl:when test="*[starts-with(name(),'fgman')]" /> <xsl:otherwise> L<xsl:value-of select="@no"/>:<xsl:value-of select="onefield"/> </xsl:otherwise> </xsl:choose> markus
"Michael Reiche" <reicheREMOVE@THISimage.dk> wrote in message news:pan.2004.02.04.19.56.54.883621@THISimage.dk... > Question on XSL expression > > Got this XML: > > <Body> > <Page> > <Line no="9" detail="true"> > <onefield>onefieldstext</onefield> > <twofield>twofieldstext</twofield> > </Line> > <Line no="10" detail="true"> > <onefield>onefieldstext</onefield> > <fgman9>fgmanfieldstext</fgman9> > <twofield>twofieldstext</twofield> > </Line> > <Line no="11" detail="true"> > <onefield>onefieldstext</onefield> > <twofield>twofieldstext</twofield> > </Line> > <Line no="12" detail="true"> > <onefield>onefieldstext</onefield> > <twofield>twofieldstext</twofield> > </Line> > <Line no="13" detail="true"> > <onefield>onefieldstext</onefield> > <fgman5>fgmanfieldstext</fgman5> > <twofield>twofieldstext</twofield> > </Line> > <Line no="14" detail="true"> > <onefield>onefieldstext</onefield> > <twofield>twofieldstext</twofield> > </Line> > </Page> > </Body> > > I would select the <Line/> nodes without text-node children whose names A text node does not have a name -- probably you mean "whose parent's name" .. > is starting with "fgman" - in this example it is all <Line/> _except_ > <fgman9/> and <fgman5/> in <Line/> with @no of 10 and 13. Use: /*/*/Line[not(*[starts-with(name(), 'fgman')])] [text()] Cheers, Dimitre Novatchev [XML MVP], FXSL developer, XML Insider, http://fxsl.sourceforge.net/ -- the home of FXSL Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
On Thu, 05 Feb 2004 06:40:45 +0100, Dimitre Novatchev [MVP] wrote: > > > A text node does not have a name -- probably you mean "whose parent's name" > . Exactly!!! > > > Use: > > /*/*/Line[not(*[starts-with(name(), 'fgman')])] [text()] > > Well actually I found: <xsl:if test="not(*[starts-with(name(), 'fgman')])"> to suit my needs. > Cheers, > > Dimitre Novatchev [XML MVP], > FXSL developer, XML Insider, > > http://fxsl.sourceforge.net/ -- the home of FXSL > Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html Thank you Dimitre. Regards, Michael Reiche