String function: concat(), upper-case(), substring() : concat « XSLT stylesheet « XML






String function: concat(), upper-case(), substring()


File: Data.xml

<?xml version="1.0" encoding="UTF-8"?><CastList xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <CastMember>
    <Character><Name>name 1</Name></Character>
    <Actor><Name>actor 1</Name></Actor>
  </CastMember>
  <CastMember>
    <Character><Name>name 2</Name></Character>
    <Actor><Name>actor 2</Name></Actor>
  </CastMember>
</CastList>

File: Transform.xslt

<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xsl:template match="ul">
      <CastList><xsl:apply-templates /></CastList>
    </xsl:template>
    
    <xsl:template match="li">
      <CastMember><xsl:apply-templates /></CastMember>
    </xsl:template>
    
    <xsl:template match="span">
      <xsl:variable name="name" as="xs:string" 
                    select="concat(upper-case(substring(@class, 1, 1)),
                                   substring(@class, 2))" />
      <xsl:element name="{$name}">
        <Name><xsl:value-of select="." /></Name>
      </xsl:element>
    </xsl:template>

</xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-8"?>
  
    name 1
    actor 1
  
  
    name 2
    actor 2
  

 








Related examples in the same category

1.concat function