Altova Mailing List Archives


Re: [xsl] call-template and execute xsl command

From: Greg Faron <gfaron@------------------>
To:
Date: 4/15/2002 10:14:00 AM
At 11:26 AM 4/15/2002, you wrote:
<xsl:template name= "attributes">

    <xsl:choose>

     <xsl:when test="@font-size">

      <xsl:attribute name="font-size"><xsl:value-of 
select="@font-size"/></xsl:attribute>

     </xsl:when>

     <xsl:when test="@text-align">

      This text prints out if @text-align but the xsl:command is not executed

      <xsl:attribute name="text-align"><xsl:value-of 
select="@text-align"/></xsl:attribute>

     </xsl:when>

    </xsl:choose>

  </xsl:template>



called like this:
 <xsl:variable name='y'>
   <xsl:call-template name='attributes'/>
 </xsl:variable>

However, as you may see by my notes above, text prints out fine
subject to the condition, however I cannot change or add
attributes as required.

  According to one site, <http://www.topxml.com/xsl/elmxsl_attribute.asp>, 
the xsl:attribute element may be contained within a xsl:when element, so 
your stylesheet is technically valid.  But, I believe you're using a 
loophole in that it really must be used within a xsl:element 
element.  Here's a quote from the site:



Element:xsl:attribute

Generates an attribute in the destination document. It should be used in 
the context of an element (either a literal, xsl:element or some other 
element that generates an element in the output). It must occur before any 
text or element content is generated.



  As a minimum-effort suggestion, I recommend modifying your variable to 
be like this:

<xsl:variable name='y'>

  <xsl:element name="'something'">

    <xsl:call-template name='attributes'/>

  </xsl:element>

</xsl:variable>



although I suspect a more hefty re-work may be necessary.  Your variable 
will probably not be a true node, so will have to be converted to a 
node-set using an extension function.  After this conversion, you'll likely 
want the first child of the new set.

<xsl:variable "y2" select="msxsl:node-set($y)"/>

<xsl:variable "y3" select="$y2/*[1]"/>




Greg Faron
Integre Technical Publishing Co.





XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.