xsl-list
[Top] [All Lists]

RE: Setting name attribute of <xsl:attribute>

2003-10-10 06:26:05
Perhaps you are calling your template with, say

<xsl:with-param name="attributeName" select="code"/>

rather than

<xsl:with-param name="attributeName" select="'code'"/>

I would think that a better solution is to pass the attribute node as a
parameter, rather than passing its name and value. Your template then
becomes:

<xsl:template name="copy-att"
<xsl:param name="attNode"/>
<xsl:if test="string(.)">
  <xsl:copy/>
</xsl:if>
</xsl:template>

and the calling code becomes, for example

<xsl:call-template name="copy-att">
  <xsl:with-param name="attNode" select="@code"/>
</

Michael Kay


-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Witham, Darren (Contractor)
Sent: 10 October 2003 12:50
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Setting name attribute of <xsl:attribute>



Hi,

  I have what I hope is an easy issue to solve but my varying 
attempts to do so have not been successful. I have an xsl 
stylesheet which transforms some xml into another xml format.
  I only wish to generate XML in the output xml file if 
attributes in the src xml exist. At present I have a number 
of <xsl:if test......> directives to check if an attribute is 
present before processing.
  I would like to remove the need for the <xsl:if test......> 
and want to call a template to do the check and process if 
need be.....

  My template is 

      <!--
        Helper template that only pushes out out XML if value 
of attribute to publish is not null 
      -->
    <xsl:template name="checkAttributeNotNull">
        <xsl:param name="attributeName"/>
        <xsl:param name="attributeValue"/>
        <xsl:if test="$attributeValue">
          <xsl:attribute name="{$attributeName}">
            <xsl:value-of select="$attributeValue" />
          </xsl:attribute>
        </xsl:if>
    </xsl:template>

 And I call if via :

  
<xsl:call-template name="checkAttributeNotNull">
     <xsl:with-param name="attributeName" select="anAttName"/>
     <xsl:with-param name="attributeValue" 
select="anAttValue"/>  </xsl:call-template> 

  The problem I have is within the template I call.  I cannot 
seem to set the name of the attribute I am trying to create 
with the parameter 'attributeName'. ( i.e with <xsl:attribute 
name="{$attributeName}">)  I have tried all sorts of 
combinations except for the correct one. I thought I could 
set this value at runtime ?????

Any pointers appreciated.

Thx

 

 

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



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



<Prev in Thread] Current Thread [Next in Thread>