Question: I am a XSLT newbie and have a simple task:

Suppose I have the following XML:

> 
> 
> ```
> <Element1>
>     <Element2 attr1="1"/>
> </Element1>
> <Element1 attr1="2"/>
> <Element1>
>     <Element2 attr1="2"/>
> </Element1>
> 
> ```
> 
> 

I want to transform the XML to the same XML with one change: All attributes named "attr1" no matter where they are have to be transformed so that for example "1" will be "A" and "2" will be "X", i. e. to

> 
> 
> ```
> <Element1>
>     <Element2 attr1="A"/>
> </Element1>
> <Element1 attr1="X"/>
> <Element1>
>     <Element2 attr1="X"/>
> </Element1>
> 
> ```
> 
> 

How can I achieve this?
Thanks in advance!

Answer: 
Another way, using `document` function:

```
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:l="local"
>
    <xsl:output method="xml" indent="yes"/>

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

    <xsl:template match="@attr1">
        <xsl:attribute name="attr1">
            <xsl:value-of select="document('')//l:item[l:in = current()]/l:out"/>
        </xsl:attribute>
    </xsl:template>

    <xml xmlns="local">
        <item>
            <in>1</in>
            <out>A</out>
        </item>
        <item>
            <in>2</in>
            <out>X</out>
        </item>
    </xml>

</xsl:stylesheet>

```
xslt 2 version below works:

```
    <xsl:output method="xml" indent="yes"/>

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

    <xsl:template match="@attr1[.='1']">
        <xsl:attribute name="attr1">
            <xsl:value-of select="replace(.,'1','A')"/>
        </xsl:attribute>
    </xsl:template>

    <xsl:template match="@attr1[.='2']">
        <xsl:attribute name="attr1">
            <xsl:value-of select="replace(.,'2','X')"/>
        </xsl:attribute>
    </xsl:template>

</xsl:stylesheet>

```