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

Subject: RE: [xsl] Change xml:lang of a skos:prefLabel [ skos, rdf, xml:lang ]
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 14 Oct 2009 23:19:45 +0100
> the application i'm working on requires 
> an xml:lang attribute for labels like skos:altLabel or skos:prefLabel.
> 
> is there a way (for a complete xsl newbie) to add such an 
> xml:lang attribute to labels that don't have one and leave 
> the rest of the thesaurus as it is with xsl?

Depending what exactly you mean by "labels like skos:altLabel or
skos:prefLabel", use the modified identity stylesheet pattern:

  <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.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

Current Thread