This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

XSLT Tree Model


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]