Q: moving test= to match=

Discussion in 'XML' started by Malcolm Dew-Jones, Mar 14, 2008.

  1. I have a test= that works but I would like to figure out how to move it
    into a match=. (Ok, that's unclear but pls keep reading.)

    Part of my XSLT file looks like this.

    <xsl:template match="@*|node()">
    <xsl:choose>
    <xsl:when test="
    count(.//w:fldSimple/@w:instr[contains(.,'FOP')=true()])=1
    and
    count(.//w:fldSimple/@w:instr[contains(.,'FOP ')=true()])=1
    and
    count(..//w:fldSimple/@w:instr[contains(.,'FOP')=true()])=2
    ">
    ... do something here ...
    </xsl:when>

    <xsl:eek:therwise>
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:template>


    As you can see, what I have is a single template that matches every node,
    and then an xsl:choose with a test= expression to handle certain nodes
    seperately. I did it this way because I could not figure out how to write
    that long test= expression as a match= expression in its own template.

    What I want would look like the following, except that this doesn't work
    of course.

    <xsl:template match="
    count(.//w:fldSimple/@w:instr[contains(.,'LOOP')=true()])=1
    and
    count(.//w:fldSimple/@w:instr[contains(.,'LOOP ')=true()])=1
    and
    count(..//w:fldSimple/@w:instr[contains(.,'LOOP')=true()])=2
    ">
    ... do something here ...
    </xsl:template>

    <xsl:template match="@*|node()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>


    My problem is that I dont understand the syntax I need to use for the
    match expression to make this work this way. The match has to select a
    set of nodes where for each node that test is true - but I don't know how
    to write that, and hence this post.

    Feedback welcome, thanks.

    Malcolm
    Malcolm Dew-Jones, Mar 14, 2008
    #1
    1. Advertising

  2. Malcolm Dew-Jones

    Pavel Lepin Guest

    Malcolm Dew-Jones <> wrote in
    <47d9c97b$>:
    > I have a test= that works but I would like to figure out
    > how to move it
    > into a match=. (Ok, that's unclear but pls keep reading.)
    >
    > As you can see, what I have is a single template that
    > matches every node, and then an xsl:choose with a test=
    > expression to handle certain nodes seperately. I did it
    > this way because I could not figure out how to write that
    > long test= expression as a match= expression in its own
    > template.
    >
    > <xsl:template match="
    >count(.//w:fldSimple/@w:instr[contains(.,'LOOP')=true()])=1
    > and
    > count(.//w:fldSimple/@w:instr[contains(.,'LOOP
    > ')=true()])=1 and
    >count(..//w:fldSimple/@w:instr[contains(.,'LOOP')=true()])=2
    > ">
    > ... do something here ...
    > </xsl:template>


    This should be a predicate.

    > My problem is that I dont understand the syntax I need to
    > use for the match expression to make this work this way.
    > The match has to select a set of nodes where for each node
    > that test is true - but I don't know how to write that,
    > and hence this post.


    I would recommend reading a good XPath tutorial. You can't
    get anywhere without XPath in XSLT anyway. IBM's
    developerWorks probably has some good introductory XPath
    materials.

    <http://www.ibm.com/developerworks/xml/>

    --
    "...a Netscape engineer who shan't be named once passed a
    pointer to JavaScript, stored it as a string and later
    passed it back to C, killing 30..." --Blake Ross
    Pavel Lepin, Mar 14, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. linkswanted
    Replies:
    0
    Views:
    912
    linkswanted
    Dec 21, 2007
  2. linkswanted
    Replies:
    0
    Views:
    1,560
    linkswanted
    Jan 6, 2008
  3. linkswanted
    Replies:
    0
    Views:
    445
    linkswanted
    Jan 23, 2008
  4. linkswanted
    Replies:
    0
    Views:
    629
    linkswanted
    Jan 24, 2008
  5. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    690
    Skybuck Flying
    Oct 4, 2009
Loading...

Share This Page