|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Element value
Magyary Endre wrote:
>I need to transform an element value to an attribute value:
>input:
><element>
><element.name>hello</element.name>
></element>
>output:
><element name="hello"/>
>I have no idea ho to refer the element's value in an xsl:template
>Thank you, Endre
for input
<element>
<element.name>hello</element.name>
<element.subject>World</element.subject>
</element>
the stylesheet :
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1">
<xsl:output method="xml" omit-xml-declaration="no" standalone="yes" media-type="text/xml" indent="yes" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="element">
<xsl:element name="element">
<xsl:for-each select="*">
<xsl:variable name="subname"><xsl:value-of select="substring-after(local-name(),'.')" /></xsl:variable>
<xsl:attribute name="{$subname}" ><xsl:value-of select="text()" /></xsl:attribute>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
results to:
<?xml version="1.0" standalone="yes"?>
<element name="hello" subject="World"></element>
HTH
JB
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








