XSLT Select nodes without text-node children whose names starts with specifix text

Michael Reiche

Usenet Archive
Joined
May 11, 2001
Messages
6
Reaction score
0
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
 

Markus Spath

Usenet Archive
Joined
Feb 6, 2003
Messages
35
Reaction score
0
Michael said:
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:eek:therwise>
L<xsl:value-of select="@no"/>:<xsl:value-of select="onefield"/> </xsl:eek:therwise> </xsl:choose>

markus
 

Dimitre Novatchev MVP

Usenet Archive
Joined
Feb 4, 2004
Messages
5
Reaction score
0
Michael Reiche said:
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
 

Michael Reiche

Usenet Archive
Joined
May 11, 2001
Messages
6
Reaction score
0

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,802
Members
249,594
Latest member
henrywalsh

Latest Threads

Top