RE: [xsl] Problems copying elements recursively.

Subject: RE: [xsl] Problems copying elements recursively.
From: Imrran Wahid <devguy2003@xxxxxxxxx>
Date: Sun, 9 Feb 2003 10:25:26 -0800 (PST)
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