[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: Elements to attributes
Subject: Re: Elements to attributes From: "Alex Albu" <xsl@xxxxxxxxxxxxxxx> Date: Thu, 26 Oct 2000 17:39:13 -0400 |
Like Michael Kay always says, think trees, not files. You want to output a tree, not a bunch of tags. > I want to transform a list of attributes (NMTOKENS) into element. I.e. from: > <foo N="PU US UK"/> > to: > <foo><St>PU</St><St>US</St><St>UK</St></foo> > > The following: > > [snip] > > > Converts it to: > <foo><St>UK</St><St>US</St><St>PU& lt;/St></ > foo> > > > Please, > > 1. How can I replace < and < with < and > in the ouput. In order to fix your style sheet you must generate elements instead of strings. <xsl:template match="foo"> <foo> <!-- <xsl:variable name="st"> --> <xsl:variable name="wlista" select="@N"/> <xsl:call-template name="lists"> <xsl:with-param name="wlist" select="$wlista"/> <xsl:with-param name="tag" select="'St'"/> </xsl:call-template> <!-- </xsl:variable> <xsl:value-of select="$st"/> --> </foo > </xsl:template> <xsl:template name="lists"> <xsl:param name="wlist"/> <xsl:param name="tag"/> <xsl:variable name="wlistb" select="concat(normalize-space($wlist),' ')"/> <xsl:choose> <xsl:when test="$wlistb!=' '"> <xsl:variable name="first" select="substring-before($wlistb,' ')"/> <xsl:variable name="rest" select="substring-after($wlistb,' ')"/> <!-- this generates the nodes in the output tree --> <!-- if the element name is not always St, use <xsl:element> --> <St><xsl:value-of select="$first"/></St> <xsl:call-template name="lists"> <xsl:with-param name="wlist" select="$rest"/> <xsl:with-param name="tag" select="$tag"/> </xsl:call-template> <!-- <xsl:value-of select="concat('<',$tag,'>',$first,'</',$tag,'>')"/> --> </xsl:when> </xsl:choose> </xsl:template> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Elements to attributes, Peter Sparkes | Thread | Re: Elements to attributes, David Carlisle |
Re: XSL and inserting values in HTM, John E. Simpson | Date | XML to PDF, Larry_Mason |
Month |