XML Tutorial/XSLT stylesheet/substring after

Материал из Web эксперт
Версия от 11:26, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Changing case of a text: substring-after() substring-before() translate()

   <source lang="xml">

File: Data.xml <?xml version="1.0" encoding="utf-8"?> <citylist>

 <distance city="A">1 HOURS</distance>
 <distance city="B">2 HOURS</distance>
 <distance city="C">30 MINUTES</distance>
 <distance city="D">HOURS HOURS</distance>
 <distance city="E">MINUTES MINUTES</distance>

</citylist> File: Transform.xslt <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet

     version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template match="citylist">
<xsl:for-each select="distance"> </xsl:for-each>
             <xsl:value-of select="@city"/>
             <xsl:text>=</xsl:text>
             <xsl:value-of select="substring-before(.," ")"/>
             <xsl:text/>
             <xsl:value-of select="translate(substring-after(.," "),"OURSINTE","oursinte")"/>
   </xsl:template>

</xsl:stylesheet> Output:

<?xml version="1.0" encoding="UTF-8"?>
A=1Hours
B=2Hours
C=30Minutes
D=HOURSHours
E=MINUTESMinutes
</source>