[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: copy attributes modifying their values, regardless

Subject: Re: copy attributes modifying their values, regardless of their names
From: Emmanuel Bégué <eb@xxxxxxxxxx>
Date: Sat, 4 Dec 2010 09:29:16 +0100
Re:  copy attributes modifying their values
Hi,

Wouldn't this work:

<xsl:template match="*">
	<xsl:copy>
		<xsl:for-each select="@*">
			<xsl:attribute name="{name()}">
				<xsl:call-template name="modify"/>
				</xsl:attribute>
			</xsl:for-each>
		<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>

...?
Regards,
EB


On Sat, Dec 4, 2010 at 8:45 AM, TW <zupftom@xxxxxxxxxxxxxx> 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.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.