RE: [xsl] Problems copying elements recursively.

Subject: RE: [xsl] Problems copying elements recursively.
From: Imrran Wahid <devguy2003@xxxxxxxxx>
Date: Sat, 8 Feb 2003 07:01:04 -0800 (PST)
I managed to get the following template to produce
some kind of output closer to a possible solution.
But it still is not right...take a look at the output:

Here's the xml:

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<?xml-stylesheet type="text/xsl" href="test1.xsl"?> 
<SomeOutput>
  <Content>
    <Code>2</Code> 
    <ID>6</ID> 
    <TranNum>1</TranNum> 
    <Items>
      <Item>
        <ItemLine>3</ItemLine> 
        <ItemAcct>6</ItemAcct> 
      </Item>
      <Item>
        <ItemLine>5</ItemLine> 
        <ItemAcct>34</ItemAcct> 
      </Item>
    </Items>
  </Content>
  <OtherDetails>
  <Title>Testing</Title> 
  <Type>E</Type> 
  <Time>12.20</Time> 
  </OtherDetails>
</SomeOutput>


Here's the template:
<?xml version="1.0" encoding="ISO-8859-1" ?> 
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml" indent="yes" /> 
<xsl:template match="/">
  <html>
    <head>
       <title>Testing</title> 
  </head>
  <body bgcolor="#B0C4DE">
    <h3>Raw XML</h3> 
    <xsl:apply-templates select="//Content" /> 
  </body>
  </html>
</xsl:template>

<xsl:template match="Content//*">
  <xsl:copy>
    <br/>
    <xsl:text>---</xsl:text>
    <xsl:if test="count(*) &gt; 0">
      <xsl:text>***</xsl:text>
    </xsl:if>
    <xsl:text>&lt;</xsl:text>
    <xsl:value-of select="name()"/>
    <xsl:text>&gt;</xsl:text>
    <xsl:value-of select="text()"/>
    <xsl:apply-templates select="*|@*"/>
    <xsl:text>&lt;/</xsl:text>
    <xsl:value-of select="name()"/>
    <xsl:text>&gt;</xsl:text>
  </xsl:copy>
</xsl:template>

<xsl:template match="//Content">
  <xsl:copy>
    <xsl:text>&lt;</xsl:text>
    <xsl:value-of select="name()"/>
    <xsl:text>&gt;</xsl:text>
    <xsl:value-of select="text()"/>
    <xsl:apply-templates select="*|@*"/>
    <br/>
    <xsl:text>&lt;/</xsl:text>
    <xsl:value-of select="name()"/>
    <xsl:text>&gt;</xsl:text>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

Here's the output:

 Raw XML
<Content> 
---<Code>2</Code> 
---<ID>6</ID> 
---<TranNum>1</TranNum> 
---***<Items> 
---***<Item> 
---<ItemLine>3</ItemLine> 
---<ItemAcct>6</ItemAcct></Item> 
---***<Item> 
---<ItemLine>5</ItemLine> 
---<ItemAcct>34</ItemAcct></Item></Items> 
</Content>


The closing tags for nested elements need to be on a
separate line. And the indenting is not right for
nested items. I was thinking that maybe a variable to
hold the indenting characters would help the
indenting. How do i implement? Or any ideas would be
welcomed.
Thanks.
 
> > Yes, I wish to display the markup for only this
> one
> > node...and all its decendants. Would the identity
> > transform help with this? I thought it was for the
> > entire document.
> > 
> > > 
> 
> You can apply it to any node set that you wish, not
> limited to the whole
> document.  You can write templates to modify the
> output as the template
> recurses through the node set.
> 
> Cheers,
> 
> Tom P
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

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


Current Thread