Re: [xsl] Value dependency between nested attributes

Subject: Re: [xsl] Value dependency between nested attributes
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Sun, 18 Oct 2009 10:23:57 -0400
I'm not 100% sure what you want to do, but I *think* the following
will put you on a path to get you there. If not the best path, at
least a path.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">

  <xsl:param name="XX">oops ? you forgot to supply an XX</xsl:param>
  <xsl:param name="YY">oops ? you forgot to supply a  YY</xsl:param>
  <xsl:param name="VV">oops ? you forgot to supply a  VV</xsl:param>
  <xsl:param name="WW">oops ? you forgot to supply a  WW</xsl:param>
  
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="A">
    <xsl:copy-of select="@*"/>
    <xsl:choose>
      <xsl:when test="@name='a'">
        <xsl:attribute name="test2"><xsl:value-of select="$XX"/></xsl:attribute>
        <xsl:attribute name="test3"><xsl:value-of select="$YY"/></xsl:attribute>
      </xsl:when>
      <xsl:when test="@name='b'">
        <xsl:attribute name="test2"><xsl:value-of select="$VV"/></xsl:attribute>
        <xsl:attribute name="test3"><xsl:value-of select="$WW"/></xsl:attribute>
      </xsl:when>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>


> Output format shall be same than input format (XML-->XML Transformation):
>  <A name="a" test1="vw" test2="cd" test3="ef" test4="gh"/>
>  <A name="b" test1="vw" test2="cd" test3="ef" test4="gh" test7="ee"/>
>  <A name="c" test1="vw" test2="cd" test3="ef" test4="gh"/>
>  <A name="d" test1="xy" test2="ij" test3="kl" test4="mn" test5="op"/>
> I want to give some params to the processor to change some (not
> all) "test" values. The values for the change depend on the value
> of the "name" attribute.
> For example: if value of name = "a" then test2 value="$XX" and
> test3 value="$YY" and if name="b" then test2 value="$VV" and test3
> value="$WW"
> There are 4 different values for 'name' --> 4 A lines
> It is my first try to build a xsl file -- so sorry if this question
> is stupid. I tried to customize the "Identity change template"
> (http://www.dpawson.co.uk/xsl/sect2/identity.html#d5687e43 ) for my
> needs, but i am not experienced enough to get this running for my
> situation.
> If someone could show me some templates to solve this problem...
> Thank you very much

Current Thread