[xsl] Changing a specific attribute value

Subject: [xsl] Changing a specific attribute value
From: "andrew cooke" <acooke@xxxxxxxx>
Date: Mon, 28 Feb 2005 18:22:31 -0300 (CLST)
Hi,

Sorry to bother you.  I'm going round in circles here and would
appreciate help with the following.

I would like to transform data like:

...
  <metadata>
    <vr:Resource xmlns:vr="http://www.ivoa.net/xml/VOResource/v0.10";
xmlns:oai="http://www.openarchives.org/OAI/2.0/";
xmlns:oxf="http://www.orbeon.com/oxf/processors";
xmlns:carn="http://www.cacr.caltech.edu/projects/us-vo/schemas/Carnivore";
xmlns:p="http://www.orbeon.com/oxf/pipeline"; xsi:type="q1:ConeSearch"
updated="2005-02-11">
      <title xmlns="http://www.ivoa.net/xml/VOResource/v0.10";
xmlns:q1="http://www.ivoa.net/xml/ConeSearch/v0.3";>Sloan Digitized Sky
Survey(DR3)</title>
      <shortName xmlns="http://www.ivoa.net/xml/VOResource/v0.10";
...

so that the "xsitype" attribute of vr:Resource has the value
"cs:ConeSearch" (yes, there's something suspicious in that q1 is
defined as a namespace abbreviation in the next element - that's not my
problem, I am treating the attribute value as a simple string)

I am trying to use the following template:

  <xsl:stylesheet version="2.0">
    <xsl:template match="vr:Resource">
      <vr:Resource>
        <xsl:apply-templates select="@*"/>
        <xsl:apply-templates select="*"/>
      </vr:Resource>
    </xsl:template>
    <xsl:template match="vr:Resource/@xsi:type[@xsi:type='q1:ConeSearch']"
                  priority="2">
      <xsl:attribute name="xsi:type">cs:ConeSearch</xsl:attribute>
    </xsl:template>
    <xsl:template match="vr:Resource/@*">
      <xsl:copy-of select="."/>
    </xsl:template>
    <xsl:template match="*">
      <xsl:copy>
        <xsl:apply-templates/>
      </xsl:copy>
    </xsl:template>
  </xsl:stylesheet>

This is inside a pipeline system, and the namespace defintions are in the
environment.  However, this is not working (the element and attributes are
copied - if I supply a different element name it is used - but the
attribute value for xsi:type is unaltered).  My questions are:

- Why isn't this changing the attribute value?

- Why do I need to explicitly apply the templates to each attribute?
  Shouldn't that be done by the built-in rules? (If I don't, it seems to
only process attributes "up to" the xsi:type).

I'm basing my solution on
http://www.stylusstudio.com/xsllist/200402/post30540.html if that
helps explain anything.

Help would be very much appreciated.  There's something I'm missing when
it comes to attributes, and I don't understand what it is.

Thanks,
Andrew

-- 
` __ _ __ ___  ___| |_____   work web site: http://www.ctio.noao.edu/~andrew
 / _` / _/ _ \/ _ \ / / -_)  personal web site: http://www.acooke.org/andrew
 \__,_\__\___/\___/_\_\___|  list: http://www.acooke.org/andrew/compute.html

Current Thread