xsl-list
[Top] [All Lists]

[xsl] Descendant::??

2008-04-22 10:20:14
Do I want to use the Descendant predicate to get all nodeset children of
the one I match on?

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
 <xsl:output encoding="UTF-8" method="html" version="4.01"
omit-xml-declaration="yes" media-type="text/html"/>
 <!-- value passed dynamically via asp -->
 <xsl:param name="paraCatagory"/>
 
 <xsl:template match="menu">
  <xsl:apply-templates
select="descendant::category[(_at_)name=$paraCatagory]"/>
 </xsl:template>
 
 <xsl:template match="category">
     <div class="cat_module">
      <xsl:value-of select="category/@display_name"/>
      <br/>
      <a href="{category/info/link}">
       <img src="{category/info/images/image}"/>
      </a>
     </div>
 </xsl:template>
</xsl:stylesheet>


Right now I am still getting only one child node-set returned and
written to the html screen, the very first node-set in each sub-category
area of the xml... 

-----Original Message-----
From: Dan Acuff [mailto:dacuff(_at_)suresource(_dot_)com] 
Sent: Tuesday, April 22, 2008 12:36 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] XSL-T should naturally loop? not grabbing all the
children node-sets..

Here is the way each child-node-set should be formatted.

<div class="cat_block">
<div class="cat_module">
sub-Category c2_sub1
<br/>
<a href="/products/c2_products/c2_sub1_products">
<img src="/imagesEdp/default_sm.jpg"/>
</a>
</div>
</div>

trouble is it stops there when it should also create html code for:

<div class="cat_block">
<div class="cat_module">
sub-Category c2_sub2
<br/>
<a href="/products/c2_products/c2_sub2_products">
<img src="/imagesEdp/default_sm.jpg"/>
</a>
</div>
</div> 

and:

<div class="cat_block">
<div class="cat_module">
sub-Category c2_sub3
<br/>
<a href="/category/c2_products/c2_sub3_products"> <!-- category becuase
this one ALSO has sub-node-sets..
<img src="/imagesEdp/default_sm.jpg"/>
</a>
</div>
</div>

-----Original Message-----
From: David Carlisle [mailto:davidc(_at_)nag(_dot_)co(_dot_)uk]
Sent: Tuesday, April 22, 2008 12:16 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] XSL-T should naturally loop? not grabbing all the
children node-sets..



perhaps something like

<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
 <xsl:output encoding="iso-8859-1" method="xml" indent="yes"/>
<xsl:param name="paraCatagory"/>

 <xsl:template match="menu">
  <xsl:apply-templates select="category[(_at_)name=$paraCatagory]"/>
 </xsl:template>

 <xsl:template match="category">
   <div class="cat_block">
     <xsl:choose>
       <xsl:when test="parent::menu">
         <xsl:attribute name="class">cat_block</xsl:attribute>
       </xsl:when>
       <xsl:otherwise>
         <xsl:attribute name="class">cat_module</xsl:attribute>
       </xsl:otherwise>
     </xsl:choose>
     <xsl:value-of select="category/@display_name"/>
     <br/>
     <a href="info/link">
       <img src="info/images/image"/>
     </a>
     <xsl:apply-templates select="category"/>
   </div>
 </xsl:template>
</xsl:stylesheet>


which makes

$ saxon loop.xml loop.xsl paraCatagory=c2_products <?xml version="1.0"
encoding="iso-8859-1"?> <div class="cat_block">sub-Category c2_sub1<br/>
   <a href="info/link">
      <img src="info/images/image"/>
   </a>
   <div class="cat_module">
      <br/>
      <a href="info/link">
         <img src="info/images/image"/>
      </a>
   </div>
   <div class="cat_module">
      <br/>
      <a href="info/link">
         <img src="info/images/image"/>
      </a>
   </div>
   <div class="cat_module">sub-sub-Category c2_sub_sub1<br/>
      <a href="info/link">
         <img src="info/images/image"/>
      </a>
      <div class="cat_module">
         <br/>
         <a href="info/link">
            <img src="info/images/image"/>
         </a>
      </div>
      <div class="cat_module">
         <br/>
         <a href="info/link">
            <img src="info/images/image"/>
         </a>
      </div>
   </div>
</div>


(I switched xsl:output to use xml indenting, just to make it clearer
what the output is)

David

--~------------------------------------------------------------------
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>
--~--


--~------------------------------------------------------------------
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>
--~--


--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>