xsl-list
[Top] [All Lists]

[xsl] How to select specific nodes using xsl:template match or similar?

2007-06-12 04:08:40
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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--