xsl-list
[Top] [All Lists]

Re: [xsl] copy attributes modifying their values, regardless of their names

2010-12-04 16:43:03
Well, firstly, "attribute value templates" are things you find in a stylesheet, not in a source document. But let's assume you mean "attribute values containing "{".

I would have thought the cleanest approach was

<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="@*[contains(., '{')]">
<xsl:attribute name="{name()}">
<xsl:value-of select="......."/>
</xsl:attribute>
</xsl:template>

Michael Kay
Saxonica

On 04/12/2010 07:45, TW wrote:
Hi all,

I'm generating XSL stylesheets using XSL.  One thing I want to do is
modify all attribute value templates found in the source document.  I
thought something like this would do the job:

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform";>
   <template name="modify-attribute-value-templates">
     Create replacement value
   </template>

   <template match="*">
     <copy>
       <for-each select="@*">
         <copy>
           <call-template name="modify-attribute-value-templates"/>
         </copy>
       </for-each>
       <apply-templates/>
     </copy>
   </template>
</stylesheet>

But much to my chagrin I realized that<copy>  already copies the value
if applied to attributes.  A workaround could be a long choose element
like this:

   <template match="*">
     <copy>
       <for-each select="@*">
         <choose>
           <when test="not(contains(string(),'{'))">
             <copy/>
           </when>
           <when test="local-name()='att1'">
             <attribute name="att1">
               <call-template name="modify-attribute-value-templates"/>
             </attribute>
           </when>
           <when test="local-name()='att2'">
             <attribute name="att2">
               <call-template name="modify-attribute-value-templates"/>
             </attribute>
           </when>
           <!-- a ton of more attributes -->
           <otherwise>
             <message terminate="yes">
               The attribute value template found in attribute
               <value-of select="local-name()"/>
               isn't handled by the stylesheet.
             </message>
           </otherwise>
         </choose>
       </for-each>
       <apply-templates/>
     </copy>
   </template>

There might be an awful lot of attributes that have to be handled.  If
I don't know what attributes are to be found in the source document,
then I I'll have to add another step to the process, creating the
above choose statement using another stylesheet.

I refuse to believe that something I thought would be done in three
lines turns out to require thousands of lines for case differentiation
and potentially an additional step in the process.  Can anyone help?

Thomas W.

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




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