----- Original Message -----
From: "Matteo Valdina" <zanfire(_at_)gmail(_dot_)com>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Thursday, October 18, 2007 8:53 AM
Subject: [xsl] Root node with attributes
Hello,
I'm tring to understand where is my error and a solution for this problem:
When the root node conatins attributes the templates are not applied,
If the root node don't contain the attributes the templates are
applied.
I didn't understand wath is the right way to apply a template in a
root node with attributes.
Any suggestion are welcome.
Thanks and sorry for my english
Matteo Valdina
Program used: saxon 8
Stylesheet
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="xml" />
<xsl:template match="*|/">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<!-- Transform a string to a Array -->
<xsl:template match="String">
<xsl:message>Convert String</xsl:message>
<Array name="{(_at_)name}">
<xsl:for-each select="string-to-codepoints(@value)">
<ArrayData type="UBYTE" value="{.}"/>
</xsl:for-each>
<ArrayData type="UBYTE" value="0"/>
</Array>
</xsl:template>
</xsl:stylesheet>
Input file:
<?xml version="1.0" encoding="UTF-8"?>
<Assembly xmlns="http://nxtassembler.sourceforge.net/NXT/AsXML.xsd">
<Dataspace>
<Data name="a" type="ULONG" value="1"/>
<String name="ciao" value="Hello!" />
</Dataspace>
</Assembly>
Te aspected result is:
<?xml version="1.0" encoding="UTF-8"?>
<Assembly xmlns="http://nxtassembler.sourceforge.net/NXT/AsXML.xsd">
<Dataspace>
<Data name="a" type="ULONG" value="1"/>> <Array
name="ciao"><ArrayData type="UBYTE" value="72"/><ArrayData
type="UBYTE" value="101"/><ArrayData type="UBYTE"
value="108"/><ArrayData type="UBYTE" value="108"/><ArrayData
type="UBYTE" value="111"/><ArrayData type="UBYTE"
value="33"/><ArrayData type="UBYTE" value="0"/></Array>
</Dataspace>
</Assembly>
Two things, the root node is different from the root element and cannot
contain attributes. It is the entry point to the document, the / in your
first template.
Secondly the xmlns part is a namespace declaration, to read about matching
nodes in a namespace see http://www.dpawson.co.uk/xsl/sect2/N5536.html,
especially numbers 13 and 23.
Joe
http://joe.fawcett.name
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--