XML technologies / XSLT / Introduction to XSLT 2.0 / Getting started with XSLT and XPath / A comparison: expression vs. instruction / The goal: A tailored sequence

(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, Chapter 1.)

This brief introduction to sequences helps solve the task: output the address container’s contents in the order street, house number, postal code, and city. After the house number, insert a comma followed by a space.

Since the surrounding element <anschrift> is the current context, a sequence of simple XPath expressions and a literal results. The literal provides the comma:

<xsl:template match="anschrift">
  <xsl:value-of select="(strasse, nr, ',', plz, ort)"/>
</xsl:template>

To obtain spaces between string values, the default value of the separator attribute makes further action unnecessary. Consequently, the comma literal needs no trailing space: it is treated just like the other sequence items. Single quotes delimit the string literal here because double quotes already delimit the attribute.

Processing and output follow the order of expressions in the sequence, independently of document order. The final result exactly matches the previously described method using several instructions.

   

back to top