xsl-list
[Top] [All Lists]

Re: How to Handle Attributes Content

2003-02-20 06:24:18
I realised that I had typographical errors when
composing this message. So here is the corrected
templates I am using.

<xsl:template match="//Content" mode="raw">
 <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="*|@*"
mode="raw-req-inner"/>
 <br/>
 <xsl:text>&lt;/</xsl:text>
 <xsl:value-of select="name()"/>
 <xsl:text>&gt;</xsl:text>
 </xsl:copy>
 </pre>
 </xsl:template>

<xsl:template match="Content//*" mode="raw-req-inner">
 <xsl:copy>
 <br/>
 <xsl:for-each select="ancestor::*[name()
='SomeInput']">
 <xsl:value-of select="$str-indent" />
 </xsl:for-each>
 <xsl:text>&lt;</xsl:text>
 <xsl:value-of select="name()"/>
 <xsl:text>&gt;</xsl:text>
 <xsl:value-of select="text()"/>
 <xsl:apply-templates select="*|@*"
mode="raw-req-inner"/>
 <xsl:if test="count(./*) &gt; 0">
 <br/>
 <xsl:for-each
select="ancestor::*[name()!='SomeInput']">
 <xsl:value-of select="$str-indent" />
 </xsl:for-each>
 </xsl:if>
 <xsl:text>&lt;/</xsl:text>
 <xsl:value-of select="name()"/>
 <xsl:text>&gt;</xsl:text>
 </xsl:copy>
 </xsl:template>



The challenge at hand is that my xml can also be in
attributes. How do I render the raw xml with
attributes and proper indentations? For instance my
xml is:

<SomeInput>
  <Content
    CodeI="2"
    ID="6">
    <Trans>
      <Tran TranNum="1" TranAmt="10.00"/>
      <Tran TranNum="2" TranAmt="12.00"/>
    </Trans>
  </Content>
</SomeInput>

Also if there were no Trans elements then the raw
xml
should be rendered as:

<SomeInput>
  <Content
    CodeI="2"
    ID="6"/>
</SomeInput>

The Content element could have an undetermined
number
of attributes.


Sorry about the mixup
Imrran

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

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



<Prev in Thread] Current Thread [Next in Thread>