Subject: [xsl] How to Handle Attributes Content From: Imrran Wahid <devguy2003@xxxxxxxxx> Date: Wed, 19 Feb 2003 20:13:46 -0800 (PST) |
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><</xsl:text> <xsl:value-of select="name()"/> <xsl:text>></xsl:text> <xsl:value-of select="text()"/> <xsl:apply-templates select="*|@*" mode="raw-req-inner"/> <br/> <xsl:text></</xsl:text> <xsl:value-of select="name()"/> <xsl:text>></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><</xsl:text> <xsl:value-of select="name()"/> <xsl:text>></xsl:text> <xsl:value-of select="text()"/> <xsl:apply-templates select="*|@*" mode="raw-req-inner"/> <xsl:if test="count(./*) > 0"> <br/> <xsl:for-each select="ancestor::*[name()!='OutputMsg']"> <xsl:value-of select="$str-indent" /> </xsl:for-each> </xsl:if> <xsl:text></</xsl:text> <xsl:value-of select="name()"/> <xsl:text>></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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Re: [xml-dev] XMLDOM Create o, asim | Thread | Re: [xsl] How to Handle Attributes , Oleg Tkachenko |
[xsl] Re: [xml-dev] XMLDOM Create o, asim | Date | RE: [xsl] Saxon is the best!!!, Rakesh |
Month |