RE: [xsl] Traverse XML Source

Subject: RE: [xsl] Traverse XML Source
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Tue, 17 Aug 2004 21:59:40 -0700 (PDT)
Sorry, the previous XSL has some error. Please use -

<?xml version="1.0"?> 
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
 
<xsl:output method="xml" indent="yes" /> 
<xsl:strip-space elements="*" />

<xsl:template match="node()">   
   <xsl:if test="count(child::*) > 0">
     <ul>
       <xsl:value-of select="name()" />
       <xsl:apply-templates />
     </ul>
   </xsl:if>
   <xsl:if test="count(child::*) = 0">
     <li>
       <xsl:value-of select="name()" />
       <xsl:apply-templates />
     </li>
   </xsl:if>
</xsl:template>
  
</xsl:stylesheet>

Regards,
Mukul

--- Mukul Gandhi <mukul_gandhi@xxxxxxxxx> wrote:

> Hi Karl,
>   Please try this XSL -
> 
> <?xml version="1.0"?> 
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> version="1.0">
>  
> <xsl:output method="xml" indent="yes" /> 
> <xsl:strip-space elements="*" />
> 
> <xsl:template match="node()">   
>    <xsl:for-each select="@*">
>      <xsl:attribute name="{name()}">
>        <xsl:value-of select="." />
>      </xsl:attribute>
>    </xsl:for-each>
>    <xsl:if test="count(child::*) > 0">
>      <ul>
>        <xsl:value-of select="name()" />
>        <xsl:apply-templates />
>      </ul>
>    </xsl:if>
>    <xsl:if test="count(child::*) = 0">
>      <li>
>        <xsl:value-of select="name()" />
>        <xsl:apply-templates />
>      </li>
>    </xsl:if>
> </xsl:template>
>   
> </xsl:stylesheet>
> 
> Regards,
> Mukul
> 
> --- "Karl J. Stubsjoen" <karl@xxxxxxxxxxxxxxxxxxxx>
> wrote:
> 
> > That is a farely predicted result... I don't know
> to
> > what depth the child
> > nodes shall occur... but each parent node should
> be
> > a <ul> and each child
> > node with child nodes should be a <UL>... with the
> > possibility of there
> > being sibling <li>'s.
> > Here is a better XML source:
> > 
> > <ABC>
> >   <A>
> >     <AB/><CD/><EF/>
> >   </A>
> >   <B>
> >     <AB/><CD/><EF/>
> >   </B>
> >   <C/>
> >   <D/>
> >   <E/>
> > </ABC>
> > 
> > And the result:
> > <ul>ABC
> >   <ul>A
> >     <li>AB</li>
> >     <li>CD</li>
> >     <li>EF</li>
> >   </ul>
> >   <ul>B
> >     <li>AB</li>
> >     <li>CD</li>
> >     <li>EF</li>
> >   </ul>
> >   <li>C</li>
> >   <li>D</li>
> >   <li>E</li>
> >   <li>F</li>
> > </ul>
> > 
> > 
> > -----Original Message-----
> > From: cking [mailto:cking@xxxxxxxxxx]
> > Sent: Tuesday, August 17, 2004 2:24 PM
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: Re: [xsl] Traverse XML Source
> > 
> > 
> > Hi Karl,
> > 
> > there are a few problems with your XSL source:
> > it contains two templates with the same match
> > attribute
> >   <xsl:template match="*">
> > which basically means: match any element.
> > Template match attributes should be unique,
> > otherwise the
> > processor does not know which of the two templates
> > to use.
> > 
> > further, your second template has no effect,
> because
> > match="@*"
> > means: match any attribute, and your XML source
> tree
> > doesn't
> > have any element with attributes.
> > 
> > you didn't show us the output you expect, but
> > something like:
> > 
> > <xsl:template match="/stuff/abc/def">
> >   <ul><xsl:apply-templates/></ul>
> > </xsl:template>
> > 
> > <xsl:template match="path | web | uid | pwd">
> >   <li><xsl:value-of select="."/></li>
> > </xsl:template>
> > 
> > will (hopefully) give you this output:
> > 
> > <ul>
> >   <li>\\path-to-server</li>
> >   <li>http://my-web-path</li>
> >   <li>9999</li>
> >   <li>monkeysee</li>
> > </ul>
> > 
> > HTH,
> > Anton Triest
> > 
> > Tuesday, August 17, 2004 10:46 PM,
> > karl@xxxxxxxxxxxxxxxxxxxx wrote:
> > >
> > > Hello,
> > > I would like a very simple XSLT transformation
> > that traverses an XML
> > > source and creates an HTML list output.  Is this
> > an identity
> > > transformation?
> > > So far, I have only been able to get anything to
> > happen on the document
> > > root, and nothing below is traversed.
> > > Thanks for the help.  ~karl
> > >
> > > Here is what I have so far,
> > > XML Source:
> > > <stuff>
> > > <abc>
> > > <def>
> > > <path>\\path-to-server</path>
> > > <web>http://my-web-path</web>
> > > <uid>9999</uid>
> > > <pwd>monkeysee</pwd>
> > > </def>
> > > </abc>
> > > </stuff>
> > >
> > > XSL Source:
> > > <xsl:template match="*">
> > >   <xsl:copy>
> > >     <xsl:apply-templates select="@*" />
> > >     <xsl:apply-templates />
> > >   </xsl:copy>
> > > </xsl:template>
> > >
> > >
> > > <xsl:template match="@*">
> > >   <li><xsl:copy-of select="." /></li>
> > > </xsl:template>
> > >
> > > <xsl:template match="*">
> > >   <li><xsl:copy-of select="." /></li>
> > > </xsl:template>
> > >
> > > </xsl:stylesheet>



		
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail 

Current Thread