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

Re: Converting siblings to children of a node.

Subject: Re: Converting siblings to children of a node.
From: Mukul Gandhi <mukulw3@xxxxxxxxx>
Date: Fri, 8 Aug 2003 02:03:19 -0700 (PDT)
xslt select children
Hi Shawn,
  i tried to solve the problem.. Below is the complete
XSL --

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="xalan">
   <xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>
   <xsl:template match="longdesc">
   <xsl:for-each select="para">
     <xsl:if test="@style = 'Normal'">
      <p>
	<xsl:value-of select="."/>
      </p>
     </xsl:if>
   <xsl:if test="((@style = 'LS1') and
(preceding-sibling::para[1][@style = 'Normal'])) ">
     <ul>
	<li>
	  <xsl:value-of select="."/>
	</li>
	<xsl:call-template name="printLI">
	   <xsl:with-param name="node_set"
select="xalan:nodeset(following-sibling::para)"/>
	</xsl:call-template>
      </ul>
   </xsl:if>
</xsl:for-each>
</xsl:template>

<xsl:template name="printLI">
  <xsl:param name="node_set"/>
  <xsl:if test="$node_set[1][@style = 'LS1']">
    <li>
      <xsl:value-of select="$node_set[1]"/>
     </li>
  </xsl:if>
  <xsl:variable name="ns">
    <xsl:for-each select="$node_set[position() &gt;
1]">
      <para style="{@style}">
        <xsl:value-of select="."/>
       </para>
     </xsl:for-each>
  </xsl:variable>
  
  <xsl:for-each select="xalan:nodeset($ns)//para">
    <xsl:if test="(position() = 1) and (@style =
'LS1')">
    <xsl:call-template name="printLI">
	<xsl:with-param name="node_set"
select="xalan:nodeset($ns)//para"/>
    </xsl:call-template>
    </xsl:if>
  </xsl:for-each> 
</xsl:template>
</xsl:stylesheet>

i have tested the XSL on Xalan and its working fine..
i have used a nodeset extension.. You may change the
specifics arrording to your processor..

Regards,
Mukul


--- "Shawn O. McKenzie" <smckenzie@xxxxxxxxxxx> wrote:
> I have a source document something like:
> 
> <longdesc>
>   <para style="Normal">This is a regular
> paragraph.</para>
>   <para style="Normal">So is this but what follows
> is a list:</para>
>   <para style="LS1">Item one</para>
>   <para style="LS1">Item two</para>
>   <para style="Normal">This is a regular
> paragraph.</para>
>   <para style="Normal">This is a regular
> paragraph.</para>
>   <para style="Normal">This is a regular
> paragraph.</para>
>   <para style="Normal">What follows is a
> list:</para>
>   <para style="LS1">Item one</para>
>   <para style="LS1">Item two</para>
>   <para style="LS1">Item three</para>
>   <para style="Normal">This is a regular
> paragraph.</para>
> </longdesc>
> 
> I would like to translate this to something like
> 
> <p>This is a regular paragraph.</p>
> <p>So is this but what follows is a list:</p>
> <ul>
>    <li>Item one<li>
>    <li>Item two<li>
> </ul>
> <p>This is a regular paragraph.</p>
> <p>This is a regular paragraph.</p>
> <p>This is a regular paragraph.</p>
> <p>What follows is a list:</p>
> <ul>
>    <li>Item one<li>
>    <li>Item two<li>
>    <li>Item three<li>
> </ul>
> <p>This is a regular paragraph.</p>
> 
> 
> I thought I could do this with something like:
> 
>        <xsl:if test="@style='LS1'">
>          <xsl:if
> test="not(preceding-sibling::para/@style='LS1')">
>            <ul>
>              <li><xsl:value-of select="."/></li>
>          </xsl:if>
> 
>          <xsl:if
> test="preceding-sibling::para/@style='LS1' and 
> following-sibling::para/@style='LS1'">
>            <li><xsl:value-of select="."/></li>
>          </xsl:if>
> 
>          <xsl:if
> test="preceding-sibling::para/@style='LS1' and 
> not(following-sibling::para/@style='LS1')">
>              <li><xsl:value-of select="."/></li>
>            </ul>
>          </xsl:if>
>        </xsl:if>
> 
> But of course that won't work. Then, I thought I
> could do it with 
> recursion, passing the current para element as a
> variable:
> 
> <xsl:template match="para[@style='LS1']">
>   <xsl:if
> test="not(preceding-sibling::para[@style='LS1'])">
>     <xsl:variable name="node">
>       <xsl:copy-of select="."/>
>     </xsl:variable>
>     <ul>
>       <xsl:call-template name="list">
>         <xsl:with-param name="listitem"
> select="$node"/>
>       </xsl:call-template>
>     </ul>
>   </xsl:if>
> </xsl:template>
> 
> <xsl:template name="list">
>   <xsl:param name="listitem"/>
>   <li><xsl:value-of select="$listitem"/></li>
>   <xsl:if
> test="following-sibling::para[@style='LS1']">
>     <xsl:call-template name="list">
>       <xsl:with-param name="listitem">
>         <xsl:copy-of
> select="following-sibling::para"/>
>       </xsl:with-param>
>     </xsl:call-template>
>   </xsl:if>
> </xsl:template>
> 
> 
> But that doesn't change the context to the
> preceding-sibling, so it loops.
> 
> Any suggestions?
> 
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

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


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.