xsl-list
[Top] [All Lists]

Re: [xsl] Transform all tags into attributes with some tags omitted

2008-05-16 00:50:48
Thanks for your quick response Michael. I will try the XSLT right away!

On Fri, May 16, 2008 at 9:24 AM, Michael Ludwig <mlu(_at_)as-guides(_dot_)com> 
wrote:
Philipp Kursawe schrieb:

<xsl:for-each
select="TAPOS|LGPLA|MATERIAL|MATKTXT|CHECKDIGIT|CHECKDIGIT2|CHECKDIGIT3|VSOLM|MEINS|PACKGROESSE"><xsl:call-template
name="item-element" /></xsl:for-each>

[...] I do not like the select statement for the tags. I would rather
like to describe the exceptions so that tag added in the future are
automatically added as attributes without changing the xslt.

Hi Philipp,

I'd use a special mode to the transform, which by default converts
elements to attributes and has exceptions in extra templates. Please
try and modify the following to suit your needs:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:template match="@*|node()"><!-- identity template -->
   <xsl:copy>
     <xsl:apply-templates select="@*|node()"/>
   </xsl:copy>
 </xsl:template>
 <xsl:template match="item">
   <xsl:copy><!-- transform elements to attributes -->
     <xsl:apply-templates select="*" mode="attr"/>
   </xsl:copy>
 </xsl:template>
 <xsl:template match="*" mode="attr"><!-- element to attribute -->
   <xsl:attribute name="{name()}">
     <xsl:value-of select="."/>
   </xsl:attribute>
 </xsl:template>
 <!-- exceptions to this rule go here -->
 <xsl:template match="MEINS | PACKGROESSE" mode="attr">
   <!-- dispatch to identity template -->
   <xsl:apply-templates select="."/>
 </xsl:template>
</xsl:stylesheet>

Michael Ludwig

--~------------------------------------------------------------------
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>
--~--





-- 
The Dude Abides!

--~------------------------------------------------------------------
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>
--~--