This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: selecting a subtree from a tree


At 05:34 AM 4/5/2002, you wrote:
><root>
>   <record>
>      <namedcell name="ordernr"/>
>      <data>1</data>
>   </record>
>   <record>
>      <namedcell name="client"/>
>      <data>client x</data>
>   </record>
>   <record>
>      <namedcell name="address"/>
>      <data>xmlstreet 15</data>
>   </record>
>   <record>
>      <namedcell name="country">

   Typo above: The tag is not closed.

>      <data>Transformatia</data>
>   </record>
></root>
>
>how can i select the 2 record of client and address and assign them to a 
>variable.  I don't need the first and last record (ordernr and country ) 
>in this nodeset.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
   <xsl:output method="html" encoding="UTF-8"/>
   <xsl:template match="/">
     <output>
       <xsl:apply-templates/>
     </output>
   </xsl:template>
   <xsl:template match="root">
     <!--
Select all children of "root" that have a child
element "namedcell".  Furthermore, that element must
have an attribute called "name" and the value of
the attribute must be either "client" or "address".
     -->
     <xsl:variable name="short-list" select="child::*[namedcell/@name='client'
                                             or
                                             namedcell/@name='address']"/>
     <xsl:copy-of select="$short-list"/>
   </xsl:template>
</xsl:stylesheet>

produced:

<output>
   <record>
     <namedcell name="client" />
     <data>client x</data>
   </record>
   <record>
     <namedcell name="address" />
     <data>xmlstreet 15</data>
   </record>
</output>



Greg Faron
Integre Technical Publishing Co.



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]