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

RE: Problems copying elements recursively.

Subject: RE: Problems copying elements recursively.
From: Imrran Wahid <devguy2003@xxxxxxxxx>
Date: Sat, 8 Feb 2003 07:01:04 -0800 (PST)
xsl output raw xml
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

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.