[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: Sun, 9 Feb 2003 10:25:26 -0800 (PST)
imrran
I got one step closer to solution of displaying the
raw xml. However the problem is the indenting. I need
to indent children for proper display under their
parents. I am thinking of storing the number of spaces
for a single indent in a variable and concatenate more
spaces to that string as each node is tested for
children. Can anyone help with a solution/idea how to
implement this?
(NB: The "***" in the template are placeholder for
another 3 spaces for indenting).

Here's the template:
<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>&#160;&#160;&#160;</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:if test="count(./*) &gt; 0">
      <br/>
    </xsl:if>
    <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>

Here's the output:

<Content>
   <CodeI>2</CodeI>
   <ID>6</ID>
   <TranNum>1</TranNum>
   ***<Items>
   ***<Item>
   <ItemLine>3</ItemLine>
   <ItemAcct>6</ItemAcct>
   ***<Misc>
   <X1>88A</X1>
   <X2>98C</X2>
</Misc>
</Item>
   ***<Item>
   <ItemLine>5</ItemLine>
   <ItemAcct>34</ItemAcct>
</Item>
</Items>
</Content>

The Output I am looking for is:

<Content>
   <CodeI>2</CodeI>
   <ID>6</ID>
   <TranNum>1</TranNum>
   <Items>
      <Item>
         <ItemLine>3</ItemLine>
         <ItemAcct>6</ItemAcct>
         <Misc>
            <X1>88A</X1>
            <X2>98C</X2>
         </Misc>
      </Item>
      <Item>
        <ItemLine>5</ItemLine>
        <ItemAcct>34</ItemAcct>
      </Item>
   </Items>
</Content>


Imrran

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