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

How to Handle Attributes Content

Subject: How to Handle Attributes Content
From: Imrran Wahid <devguy2003@xxxxxxxxx>
Date: Wed, 19 Feb 2003 20:13:46 -0800 (PST)
xml inner text
I have the following XML:

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

And I am transforming it so that it is rendered as raw
XML with indentations similar to the above.

I use the following templates to do that:

<xsl:template match="//Content" mode="raw">
  <!-- This template outputs the request as raw xml
-->
  <pre style="color: blue; font-weight: bold;">
    <!--xsl:call-template name="xml-to-string" /-->
  <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()!='OutputMsg']">
      <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()!='OutputMsg']">
        <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.

Your help/ideas would be helpful.

I'm still awaiting 3 books I ordered on-line to help
me get up to speed with xsl. For now I can only
stretch my limited knowledge, and of course ask you
guys when I'm stumped. Well I'm stumped. Again!

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


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.