XML/XSLT stylesheet/ancestor or self

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

ancestor-or-self demo

   <source lang="xml">

File: Data.xml <chapter>

 <section xml:lang="de">
   <warning>this is a test</warning>
 </section>

</chapter> File: Transform.xslt <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

 version="1.0">
 <xsl:output method="xml" omit-xml-declaration="yes" indent="no" />
 <xsl:template match="warning">
   <xsl:if test="ancestor-or-self::*[@xml:lang][1]/@xml:lang="en"">

Warning! <xsl:apply-templates />

   </xsl:if>
   <xsl:if
     test="ancestor-or-self::*[@xml:lang][1]/@xml:lang="de"">

test! <xsl:apply-templates />

   </xsl:if>
 </xsl:template>
 

</xsl:stylesheet> Output:


test!this is a test

</source>