XML referens

XSLT

Överst i XML fil
<?xml version="1.0" encoding="utf-8"?>
<!-- filnamn.xml -->
<?xml-stylesheet type="text/xsl" href="filnamn.xsl"?>
<ROOT>
...

Överst i XSL fil
<?xml version="1.0"?>
<xsl:stylesheet version = "1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
...


<xsl:template match="/ROT">
 <html>
 <b><xsl:value-of select="NAMN"/></b>
 <i><xsl:value-of select="STAD"/></i>
 </html>
</xsl:template>

<ROT>
   <NAMN>Lars</NAMN>
   <STAD>Skara</STAD>
</ROT>


<xsl:template match="/">
 <html>
 <xsl:apply-templates/> Utför för varje funnen template match nedan
 </html>
</xsl:template>

<xsl:template match="LISTA/PERSON">
 <b><xsl:value-of select="NAMN"/></b>
 <i><xsl:value-of select="STAD"/></i>
</xsl:template>


<xsl:template match="/">
<html>
 <xsl:for-each select="LISTA/PERSON">
  <b><xsl:value-of select="NAMN"/></b>
  <i><xsl:value-of select="STAD"/></i>
 </xsl:for-each>
</html>
</xsl:template>


<xsl:template match="/SAMLING/BOK"> alla samling/bok element underordnat rotelementet
<xsl:template match="PERSON/NAMN"> alla namnelement underordnat person
<xsl:template match="//BOK"> Alla BOK-element underordnad rotnoden. d.v.s alla BOK element
<xsl:template match="PERSON//NAMN"> Alla NAMN element som som är underordnade ett PERSON element
<xsl:template match="PERSON/@name"> Attribut värde
<xsl:value-of select="."/> Kontextnoden
<xsl:value-of select=".."/> Överordnad kontextnoden
<xsl:value-of select="SAMLINGAR/*"/> Alla element underordnad SAMLINGAR
<xsl:value-of select="NAMN/@*"/> Alla attribut
<xsl:value-of select="NAMN | ORT"/> Kombinera lägesökvägar
<xsl:value-of select="El/text()"/> Alla textnoder underordnat ett El element
<xsl:value-of select="El/node"/> Alla noder


Filtrering inom [...]
<xsl:template match="PERSON[1]"> Första elementet
<xsl:template match="PERSON[END]"> Sista elementet
<xsl:template match="PERSON[@AGE>20]"> Attribut age > 20, även >=
<xsl:template match="SIDOR[.&lt;300]"> sidor < 300, även &lt;=
<xsl:template match="SAMLING[MEDIA='CD']"> Även !=
<xsl:template match="SAMLING/MEDIA[CD]">
<xsl:template match="FLOWERS[not(color='blue')]">


<xsl:for-each select="/comment()">
<xsl:value-of select="."/>
</xsl:for-each>

<xsl:for-each select="/processing-instruction()">
<xsl:value-of select="."/>
</xsl:for-each>


<xsl:value-of select = "sum(BOK/SIDOR)"/> min,max,avg...


<xsl:for-each select="PERSONER"
  <xsl:sort select="PERSON/NAMN"
    data-type="text"
    order="ascending"/>
  <xsl:sort select="PERSON/ALDER"
    data-type="number"
    order="descending"/>
  <xsl:value-of select="NAMN"/>
  (<xsl:value-of select="ALDER"/> år)<br>
</xsl:for-each>


<xsl:for-each select="BOKLISTA/BOK">
  <SPAN>
    <xsl:attribute name="STYLE">
      color: <xsl:value-of select="COLOR"/>
    </xsl:attribute>
  </SPAN>
</xsl:for-each>


Villkorssatser

<xsl:if test="@Color = 'Blue'">Specialbeställning!</xsl:if>

<xsl:choose>
  <xsl:when test="color = red">röd</xsl:when>
  <xsl:when test="color = green">grön</xsl:when>
  <xsl:otherwise>Annan</xsl:otherwise>
</xsl:choose>


Visa exempel 1 xml fil xsl fil
Visa exempel 2 xml fil xsl fil
Visa exempel 3 xml fil xsl fil
Visa exempel 4 xml fil xsl fil
Visa exempel 5 xml fil xsl fil
Visa exempel 6 xml fil xsl fil

Tillbaka