Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   Q: moving test= to match= (http://www.velocityreviews.com/forums/t598571-q-moving-test-to-match.html)

Malcolm Dew-Jones 03-14-2008 01:40 AM

Q: moving test= to match=
 
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:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:otherwise>
</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

Pavel Lepin 03-14-2008 08:28 AM

Re: Q: moving test= to match=
 

Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> wrote in
<47d9c97b$1@news.victoria.tc.ca>:
> 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


All times are GMT. The time now is 04:13 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57