Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Q: moving test= to match=

Reply
Thread Tools

Q: moving test= to match=

 
 
Malcolm Dew-Jones
Guest
Posts: n/a
 
      03-14-2008
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>

<xsltherwise>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsltherwise>
</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
 
Reply With Quote
 
 
 
 
Pavel Lepin
Guest
Posts: n/a
 
      03-14-2008

Malcolm Dew-Jones <(E-Mail Removed)> wrote in
<47d9c97b$(E-Mail Removed)>:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving Guide Moving Companies Movers Storage linkswanted ASP .Net 0 01-23-2008 01:08 AM
Free Moving Estimate, Local Movers, Long Distance Moving, PackingSupplies, Storage Rental, Home Moving, Apartment Moving, Office Moving,Commercial Moving linkswanted ASP .Net 0 01-06-2008 04:45 AM
Moving to California Moving to L.A linkswanted Digital Photography 3 01-05-2008 04:22 PM
movers los angeles moving storage services movers in L.A companymoving companies moving in calfornia los angeles linkswanted HTML 0 12-21-2007 10:55 PM



Advertisments