|
Subject: Re: [xsl] Assigning new attribute value From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 20 Dec 2016 20:25:00 -0000 |
Try
<Location>
<xsl:attribute name="{name(@*[1])}" select="$placement-index"/>
</Location>
The [1] isn't necessary if you know there will always be exactly one
attribute, but it makes it a bit more robust.
Michael Kay
Saxonica
> On 20 Dec 2016, at 20:11, Mark Wilson pubs@xxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> I am doing an identity transformation that has presented me with a problem.
The element <Location> in the original XML must have one and only one of seven
possible attributes. Whichever attribute is present, I must keep its name but
change its value. I have created a brute-force template that I assume will
work. It ascertains the attribute's name and assigns it a new value. This is
so ugly I am hanging my head in shame. There must be a more elegant method
> Mark
>
> xsl:template match="Location">
> <xsl:param name="placement-index"/>
> <Location>
> <xsl:choose>
> <xsl:when test="@minisheet">
> <xsl:attribute name="minisheet"
select="$placement-index"/>
> </xsl:when>
> <xsl:when test="@souvenir-sheet">
> <xsl:attribute name="souvenir-sheet"
select="$placement-index"/>
> </xsl:when>
> <xsl:when test="@gutter">
> <xsl:attribute name="gutter" select="$placement-index"/>
> </xsl:when>
> </xsl:choose>
>
> <!-- There are more attribute names, but you get the idea -->
>
> </Location>
> </xsl:template>
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Assigning new attribute value, Mark Wilson pubs@xxx | Thread | Re: [xsl] Assigning new attribute v, Mark Wilson mark@xxx |
| [xsl] Assigning new attribute value, Mark Wilson pubs@xxx | Date | Re: [xsl] Assigning new attribute v, Martin Honnen martin |
| Month |