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

XSLT Tree Model

Subject: XSLT Tree Model
From: "WATKIN-JONES,ADAM (HP-UnitedKingdom,ex1)" <adam_watkin-jones@xxxxxx>
Date: Thu, 4 Oct 2001 12:17:33 +0100
xslt tree
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
  • XSLT Tree Model
    • WATKIN-JONES,ADAM (HP-UnitedKingdom,ex1) - Thu, 4 Oct 2001 07:28:11 -0400 (EDT) <=

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.