I have a following xml:
<?xml version="1.0"?>
<?xml-stylesheet href="XSLTFile1.xsl" type="text/xsl" title="default
stylesheet"?>
<setings>
<applicationInfo>
<node name="Vendor" value=""/>
<node name="Name" value="Thunderbird"/>
<node name="ID" value="{3550f703-e582-4d05-9a08-453d09bdfdc6}"/>
<node name="Version" value="2.0.0.21"/>
<node name="AppBuildID" value="2009030215"/>
<node name="PlatformVersion" value="1.8.1.21"/>
<node name="PlatformBuildID" value="2009030215"/>
</applicationInfo>
<accounts>
<account key="account1">
<incomingserver key="server1">
<node name="type" value="none"/>
<node name="prettyName" value="Local Folders"/>
<node name="hostName" value="Local Folders"/>
</incomingserver>
</account>
<account key="account2">
<incomingserver key="server2">
<node name="type" value="pop3"/>
<node name="prettyName" value="aa@aa"/>
<node name="hostName" value="aa"/>
</incomingserver>
</account>
</accounts>
</setings>
and following xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="export-window" title="Example"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<tree flex="1">
<treecols>
<treecol id="idName" label="Name" flex="1" primary="true"/>
<treecol id="idValue" label="Value" flex="2"/>
</treecols>
<treechildren>
<xsl:apply-templates/>
</treechildren>
</tree>
</window>
</xsl:template>
<xsl:template match="node">
<treeitem>
<treerow>
<xsl:element name="treecell">
<xsl:attribute name="label">
<xsl:value-of select="@name"/>
</xsl:attribute>
</xsl:element>
<xsl:element name="treecell">
<xsl:attribute name="label">
<xsl:value-of select="@value"/>
</xsl:attribute>
</xsl:element>
</treerow>
</treeitem>
</xsl:template>
<xsl:template match="account|incomingserver">
<treeitem container="true" open="true">
<treerow>
<xsl:element name="treecell">
<xsl:attribute name="label">
<xsl:value-of select="@key"/>
</xsl:attribute>
</xsl:element>
</treerow>
<treechildren>
<xsl:apply-templates/>
</treechildren>
</treeitem>
</xsl:template>
<xsl:template match="accounts">
<treeitem container="true" open="true">
<treerow>
<treecell label="accounts"/>
</treerow>
<treechildren>
<xsl:apply-templates/>
</treechildren>
</treeitem>
</xsl:template>
<xsl:template match="applicationInfo">
<treeitem container="true" open="true">
<treerow>
<treecell label="applicationInfo"/>
</treerow>
<treechildren>
<xsl:apply-templates/>
</treechildren>
</treeitem>
</xsl:template>
</xsl:stylesheet>
Problem is that when is transformation I get unwanted xmlns attribute
for element applicationInfo and accounts
I get this:
<treeitem container="true" open="true" xmlns="">
1. How to ban to add this attribute to output xml?
2. Does it exist way how to get name of element that match template and
use it in template? I want to do something like I highlighted by >>>
and <<<. I want to put name of element to attribute value.
<xsl:template match="applicationInfo">
<treeitem container="true" open="true">
<treerow>
<treecell label=" >>>applicationInfo<<< "/>
</treerow>
<treechildren>
<xsl:apply-templates/>
</treechildren>
</treeitem>
</xsl:template>
thanks
PM-
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xml" indent="yes"/>
>
> <xsl:template match="/">
> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
> <window id="export-window" title="Example"
> xmlns:html="http://www.w3.org/1999/xhtml"
>
> xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
Move those namespace declarations to the xsl:stylesheet root element if
you want them to be in scope for literal result elements in all templates:
<xsl:stylesheet
xmlns:xs="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml">
That way you won't get those
> <xsl:template match="node">
> <treeitem>
xmlns="" later on here.
> 2. Does it exist way how to get name of element that match template and
> use it in template? I want to do something like I highlighted by >>>
> and <<<. I want to put name of element to attribute value.
>
> <xsl:template match="applicationInfo">
> <treeitem container="true" open="true">
> <treerow>
> <treecell label=" >>>applicationInfo<<< "/>
<treecell label="{name()}"/>
--
Martin Honnen
http://msmvps.com/blogs/martin_honnen/
PM-