[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: How to select specific nodes using xsl:template ma

Subject: RE: How to select specific nodes using xsl:template match or similar?
From: "Bhaskar Venkateswaran" <bhaskarji@xxxxxxxxxxx>
Date: Tue, 12 Jun 2007 11:34:57 +0000
RE:  How to select specific nodes using xsl:template ma
Thanks Michael and Martin, for the quick responses!

----Original Message Follows----
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: RE: How to select specific nodes using xsl:template match or similar?
Date: Tue, 12 Jun 2007 12:25:10 +0100


You can rewrite this:

    <xsl:for-each select="data">
      <xsl:variable name="date" select="@name"/>
      <xsl:if test="$date &gt;= $startDate and $date &lt;= $endDate">
        <xsl:value-of select="$date"/>
      </xsl:if>
    </xsl:for-each>

as this:

    <xsl:for-each select="data[@name &gt;= $startDate and @name &lt;=
$endDate]">
        <xsl:value-of select="@name"/>
    </xsl:for-each>

or as

<xsl:apply-templates select="data[@name &gt;= $startDate and @name &lt;=
$endDate]"/>


<xsl:template match="data">
  <xsl:value-of select="@name"/>
</xsl:template>

or even as

<xsl:apply-templates select="data"/>

<xsl:template match="data[@name &gt;= $startDate and @name &lt;= $endDate]">
  <xsl:value-of select="@name"/>
</xsl:template>

(but this last one can't be used with a conformant 1.0 processor - variables
are not allowed in a match pattern).

Don't expect any significant differences in performance (it might be that
one processor does one of these better than the others, but another
processor might do the opposite).

I am trying to use xsl:for-each-group
> method for the first time in an XSL and tried running it
> using Xalan

Xalan is an XSLT 1.0 processor. You need a 2.0 processor such as Saxon.

Michael Kay
http://www.saxonica.com/



> -----Original Message-----
> From: Bhaskar Venkateswaran [mailto:bhaskarji@xxxxxxxxxxx]
> Sent: 12 June 2007 12:07
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  How to select specific nodes using
> xsl:template match or similar?
>
> Hi,
>
> I tried posting twice before but couldn't get the code
> inserted - sorry about that.
>
> Here's is a snippet of an XML I have:
>
> <?xml version="1.0"?>
> <rep>
>   <data name = "20050102">
>     <data name = "AAA">
>     </data>
>     <data name = "BBB">
>     </data>
>   </data>
>   <data name = "20050103">
>     <data name = "AAA">
>     </data>
>   </data>
>   <data name = "20050104">
>     <data name = "BBB">
>     </data>
>     <data name = "CCC">
>     </data>
>   </data>
> </rep>
>
> My objective is to choose all first-level data nodes (i.e,
> nodes with names 20050102, 20050103 & 20050104 above) within
> a specified range of dates. In other words, what is the best
> way to, say, choose only the nodes whose name-value is
> between 20050102 and 20050103 (both inclusive). I want to be
> able to choose such nodes at the top-level WITHOUT using a
> for-each loop.
> That is, I don't want to do something like this because here
> I am running through all nodes that meet my condition as
> opposed to just selecting all such nodes in one query:
>
>   <xsl:variable name="startDate">20050102</xsl:param>
>   <xsl:variable name="endDate">20050103</xsl:param>
>   <xsl:template match="rep">
>     <xsl:for-each select="data">
>       <xsl:variable name="date" select="@name"/>
>       <xsl:if test="$date &gt;= $startDate and $date &lt;= $endDate">
>         <xsl:value-of select="$date"/>
>       </xsl:if>
>     </xsl:for-each>
> </xsl:template>
>
> Hope I am clear. Any help/idea is much appreciated.
>
> Another question: I am trying to use xsl:for-each-group
> method for the first time in an XSL and tried running it
> using Xalan (C version 1.10.0) with Xerces (C version 2.7.0)
> but I get the following warning:
>
> XSLT Warning: The element xsl:for-each-group is an unknown
> XSLT element.
> (sample.xsl, line 34, column 71.)
>
> Does it mean I need to upgrade?
>
> Thanks,
> Bhaskar
>
> _________________________________________________________________
> Career Aptitude Test. Based on the most scientific MBT Test.
> http://ss1.richmedia.in/recurl.asp?pid=64

_________________________________________________________________
Get Married in 2007. Join Shaadi.com FREE! http://www.shaadi.com/ptnr.php?ptnr=mhottag


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.