xsl-list
[Top] [All Lists]

Re: [xsl] Change xml:lang of a skos:prefLabel [ skos, rdf, xml:lang ]

2009-10-15 03:12:39
thanks all for the help,

based on the first answer from ken, i'm doing the following
which does exactly what i want


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

<xsl:template 
match="skos:prefLabel|skos:altLabel|skos:hiddenLabel|skos:definition|skos:scopeNote[not(@xml:lang)]">
   <xsl:copy>
     <xsl:attribute name="xml:lang">en</xsl:attribute>
     <xsl:apply-templates select="@*|node()"/>
   </xsl:copy>
</xsl:template>

<xsl:template match="@*|node()"><!--identity for all other nodes-->
   <xsl:copy>
     <xsl:apply-templates select="@*|node()"/>
   </xsl:copy>
</xsl:template>

</xsl:stylesheet>


wkr www.turnguard.com

----- Original Message -----
From: "Syd Bauman" <Syd_Bauman(_at_)Brown(_dot_)edu>
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Sent: Thursday, October 15, 2009 2:39:48 AM GMT +01:00 Amsterdam / Berlin / 
Bern / Rome / Stockholm / Vienna
Subject: RE: [xsl] Change xml:lang of a skos:prefLabel [ skos, rdf, xml:lang ]

  <xsl:template match="skos:altLabel|skos:prefLabel">
    <xsl:copy>
      <xsl:attribute name="xml:lang">en</xsl:attribute>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

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

This relies on the fact that if you add the same attribute to an element
twice, the last one wins.

1) Is that true for both XSLT 1 and 2 ? 

2) No disrespect intended, but something looks amiss here to me. I
   notice there is a separate <copy-of> for the attributes, but then
   templates are applied for the attributes, too. And what does a <copy-of>
   that's a child of <copy> do, anyway?

   Ah. To answer my own question, I just ran a tiny stylesheet with
   the above identity template on itself, and got the following result.

--------- output of this stylesheet on itself ---------
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="1.0">1.0
  <xsl:template match="/">/
    <xsl:apply-templates select="node()">node()</xsl:apply-templates>
  </xsl:template>
  <xsl:template match="*">*
    <xsl:copy>
      <xsl:copy-of select="@*">@*</xsl:copy-of>
      <xsl:apply-templates select="@*|node()">@*|node()</xsl:apply-templates>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>
--------- end output ---------
   So I think that's not what M. Kay meant -- I suspect the <copy-of>
   is a holdover from a previous version or a copy-and-paste error or
   some such.

   Either that or I've missed something, in which case I'm hoping
   someone explains it!

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--