[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] XSLT Tree Model
Subject: [xsl] XSLT Tree Model From: "WATKIN-JONES,ADAM (HP-UnitedKingdom,ex1)" <adam_watkin-jones@xxxxxx> Date: Thu, 4 Oct 2001 12:17:33 +0100 |
Hello! To understand the XSLT Tree Model better, I thought it would be a good idea to write a stylesheet that transformed an XML document into its tree representation. Below is an attempt at this! Questions: 1. I wanted to find namespace nodes by catching them in a template as I do for all other node types. However, I could not find a way of doing this and resorted to for-each. Could anyone suggest how to catch namespace nodes with a template instead? 2. Is there a better/more economical/more succinct way of writing this stylesheet? 3. Have I caught all the constituents of the tree model and their properties or have I missed some? Thanks for your time! Adam <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <root localName="{local-name()}" namespaceURI="{namespace-uri()}"> <xsl:for-each select="namespace::*"> <ns localName="{local-name()}" nsURI="{namespace-uri()}" value="{.}"/> </xsl:for-each> <xsl:apply-templates select="child::node()|attribute::*"/> </root> </xsl:template> <xsl:template match="*"> <element localName="{local-name()}" namespaceURI="{namespace-uri()}"> <xsl:for-each select="namespace::*"> <ns localName="{local-name()}" nsURI="{namespace-uri()}" value="{.}"/> </xsl:for-each> <xsl:apply-templates select="child::node()|attribute::*"/> </element> </xsl:template> <xsl:template match="processing-instruction()"> <pi localName="{local-name()}" nsURI="{namespace-uri()}" value="{.}"/> </xsl:template> <xsl:template match="comment()"> <comment localName="{local-name()}" nsURI="{namespace-uri()}" value="{.}"/> </xsl:template> <xsl:template match="@*"> <attribute localName="{local-name()}" nsURI="{namespace-uri()}" value="{.}"/> </xsl:template> <xsl:template match="text()"> <text localName="{local-name()}" nsURI="{namespace-uri()}" value="{.}"/> </xsl:template> </xsl:stylesheet> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Giving values to xsl:vari, Wendell Piez | Thread | Re: [xsl] XSLT Tree Model, David Carlisle |
[xsl] Giving values to xsl:variable, Ofer Kalisky | Date | [xsl] testing for existence of an e, Irene Hall |
Month |