The Extensible Stylesheet Language
Two parts:
A transformation language (XSLT)
A formatting language (XSL-FO)
This talk covers:
XSL Transformations: November 16, 1999 1.0 Specification
XSLT 1.1 and 2.0 are under development, but will build on XSLT 1.0 rather than replacing it.
The XML parser reads an XML document and forms a tree
The tree is passed to the XSLT processor
The XSLT processor compares the nodes in the tree to the instructions in the style sheet
When the XSLT processor finds a match, it outputs a tree fragment
(Optional) The complete output tree is serialized to some other format such as text, HTML, or an XML file
<?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <category> Small chamber ensembles - 2-4 Players by New York Women Composers </category> <cataloging_info> <abstract>Compositions by the members of New York Women Composers</abstract> <keyword>music publishing</keyword> <keyword>scores</keyword> <keyword>women composers</keyword> <keyword>New York</keyword> </cataloging_info> <last_updated>July 28, 1999</last_updated> <copyright>1999 New York Women Composers</copyright> <maintainer email="elharo@metalab.unc.edu" url="http://www.macfaq.com/personal.html"> <name> <first_name>Elliotte</first_name> <middle_name>Rusty</middle_name> <last_name>Harold</last_name> </name> </maintainer> <composer id="c1"> <name> <first_name>Julie</first_name> <middle_name></middle_name> <last_name>Mandel</last_name> </name> </composer> <composer id="c2"> <name> <first_name>Margaret</first_name> <middle_name>De</middle_name> <last_name>Wys</last_name> </name> </composer> <composer id="c3"> <name> <first_name>Beth</first_name> <middle_name></middle_name> <last_name>Anderson</last_name> </name> </composer> <composer id="c4"> <name> <first_name>Linda</first_name> <middle_name></middle_name> <last_name>Bouchard</last_name> </name> </composer> <composition composer="c1"> <title>Trio for Flute, Viola and Harp</title> <date><year>(1994)</year></date> <length>13'38"</length> <instruments>fl, hp, vla</instruments> <description> <p>Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements :</p> <ul> <li>mvt. 1: 5:01</li> <li>mvt. 2: 4:11</li> <li>mvt. 3: 4:26</li> </ul> </description> <publisher>Theodore Presser</publisher> </composition> <composition composer="c2"> <title>Charmonium</title> <date><year>(1991)</year></date> <length>9'</length> <instruments>2 vln, vla, vc</instruments> <description> Commissioned as quartet for the Meridian String Quartet. Sonorous, bold. Moderate difficulty. Tape available. </description> <publisher></publisher> </composition> <composition composer="c1"> <title>Invention for Flute and Piano</title> <date><year>(1994)</year></date> <length></length> <instruments>fl, pn</instruments> <description>3 movements</description> <publisher></publisher> </composition> <composition composer="c3"> <title>Little Trio</title> <date><year>(1984)</year></date> <length>4'</length> <instruments>fl, guit, va</instruments> <description></description> <publisher>ACA</publisher> </composition> <composition composer="c3"> <title>Dr. Blood's Mermaid Lullaby</title> <date><year>(1980)</year></date> <length>3'</length> <instruments>fl or ob, or vn, or vc, pn</instruments> <description></description> <publisher>ACA</publisher> </composition> <composition composer="c3"> <title>Trio: Dream in D</title> <date><year>(1980)</year></date> <length>10'</length> <instruments>fl, pn, vc, or vn, pn, vc</instruments> <description> Rhapsodic. Passionate. Available on CD <cite><a href="http://www.amazon.com/exec/obidos/ASIN/B000007NMH/qid%3D913265342/sr%3D1-2/">Two by Three</a></cite> from North/South Consonance (1998). </description> <publisher></publisher> </composition> <composition composer="c4"> <title>Propos II</title> <date><year>(1985)</year></date> <length>11'</length> <instruments>2 tpt</instruments> <description>Arrangement from Propos</description> <publisher></publisher> </composition> <composition composer="c4"> <title>Rictus En Mirroir</title> <date><year>(1985)</year></date> <length>14'</length> <instruments>fl, ob, hpschd, vc</instruments> <description></description> <publisher></publisher> </composition> </catalog>
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> </xsl:stylesheet>
Let's use xt to apply this stylesheet to compositions.xml.
Windows executable:
C:> xt compositions.xml sheet1.xsl
Java executable:
C:> java -Dcom.jclark.xsl.sax.parser=com.jclark.xml.sax.CommentDriver com.jclark.xsl.sax.Driver compositions.xml sheet1.xsl output1.html
<?xml version="1.0" encoding="utf-8"?> Small chamber ensembles - 2-4 Players by New York Women Composers Compositions by the members of New York Women Composers music publishing scores women composers New York July 28, 1999 1999 New York Women Composers Elliotte Rusty Harold Julie Mandel Margaret De Wys Beth Anderson Linda Bouchard Trio for Flute, Viola and Harp (1994) 13'38" fl, hp, vla Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements : mvt. 1: 5:01 mvt. 2: 4:11 mvt. 3: 4:26 Theodore Presser Charmonium (1991) 9' 2 vln, vla, vc Commissioned as quartet for the Meridian String Quartet. Sonorous, bold. Moderate difficulty. Tape available. Invention for Flute and Piano (1994) fl, pn 3 movements Little Trio (1984) 4' fl, guit, va ACA Dr. Blood's Mermaid Lullaby (1980) 3' fl or ob, or vn, or vc, pn ACA Trio: Dream in D (1980) 10' fl, pn, vc, or vn, pn, vc Rhapsodic. Passionate. Available on CD Two by Three from North/South Consonance (1998). Propos II (1985) 11' 2 tpt Arrangement from Propos Rictus En Mirroir (1985) 14' fl, ob, hpschd, vcView in Netscape
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="composition"> <h3><xsl:value-of select="title"/></h3> </xsl:template> </xsl:stylesheet>View Transformed Document in Netscape
<?xml version="1.0" encoding="utf-8"?> Small chamber ensembles - 2-4 Players by New York Women Composers Compositions by the members of New York Women Composers music publishing scores women composers New York July 28, 1999 1999 New York Women Composers Elliotte Rusty Harold Julie Mandel Margaret De Wys Beth Anderson Linda Bouchard <h3>Trio for Flute, Viola and Harp</h3> <h3>Charmonium</h3> <h3>Invention for Flute and Piano</h3> <h3>Little Trio</h3> <h3>Dr. Blood's Mermaid Lullaby</h3> <h3>Trio: Dream in D</h3> <h3>Propos II</h3> <h3>Rictus En Mirroir</h3>
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> </body> </html> </xsl:template> <xsl:template match="composition"> <h3><xsl:value-of select="title"/></h3> </xsl:template> </xsl:stylesheet>View Transformed Document in Netscape
<html> <body> </body> </html>
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="composition"> <h3><xsl:value-of select="title"/></h3> </xsl:template> </xsl:stylesheet>
<html> <body> Small chamber ensembles - 2-4 Players by New York Women Composers Compositions by the members of New York Women Composers music publishing scores women composers New York July 28, 1999 1999 New York Women Composers Elliotte Rusty Harold Julie Mandel Margaret De Wys Beth Anderson Linda Bouchard <h3>Trio for Flute, Viola and Harp</h3> <h3>Charmonium</h3> <h3>Invention for Flute and Piano</h3> <h3>Little Trio</h3> <h3>Dr. Blood's Mermaid Lullaby</h3> <h3>Trio: Dream in D</h3> <h3>Propos II</h3> <h3>Rictus En Mirroir</h3> </body> </html>
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <xsl:apply-templates select="catalog"/> </html> </xsl:template> <xsl:template match="catalog"> <head> <title><xsl:value-of select="category"/></title> </head> <body> <h1><xsl:value-of select="category"/></h1> <xsl:apply-templates select="composition"/> </body> </xsl:template> <xsl:template match="composition"> <h3><xsl:value-of select="title"/></h3> </xsl:template> </xsl:stylesheet>View Transformed Document in Netscape
<html> <head> <title> Small chamber ensembles - 2-4 Players by New York Women Composers </title> </head> <body> <h1> Small chamber ensembles - 2-4 Players by New York Women Composers </h1> <h3>Trio for Flute, Viola and Harp</h3> <h3>Charmonium</h3> <h3>Invention for Flute and Piano</h3> <h3>Little Trio</h3> <h3>Dr. Blood's Mermaid Lullaby</h3> <h3>Trio: Dream in D</h3> <h3>Propos II</h3> <h3>Rictus En Mirroir</h3> </body> </html>
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <xsl:apply-templates select="catalog"/> </html> </xsl:template> <xsl:template match="catalog"> <head> <title><xsl:value-of select="category"/></title> </head> <body> <h1><xsl:value-of select="category"/></h1> <xsl:apply-templates select="composition"/> <hr/> Copyright <xsl:value-of select="copyright"/><br/> Last Modified: <xsl:value-of select="last_updated"/> </body> </xsl:template> <xsl:template match="composition"> <h3><xsl:value-of select="title"/></h3> <ul> <li><xsl:value-of select="date"/></li> <li><xsl:value-of select="length"/></li> <li><xsl:value-of select="instruments"/></li> <li><xsl:value-of select="publisher"/></li> </ul> <p><xsl:value-of select="description"/></p> </xsl:template> </xsl:stylesheet>View Transformed Document in Netscape
<html> <head> <title> Small chamber ensembles - 2-4 Players by New York Women Composers </title> </head> <body> <h1> Small chamber ensembles - 2-4 Players by New York Women Composers </h1> <h3>Trio for Flute, Viola and Harp</h3> <ul> <li>(1994)</li> <li>13'38"</li> <li>fl, hp, vla</li> <li>Theodore Presser</li> </ul> <p> Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements : mvt. 1: 5:01 mvt. 2: 4:11 mvt. 3: 4:26 </p> <h3>Charmonium</h3> <ul> <li>(1991)</li> <li>9'</li> <li>2 vln, vla, vc</li> <li> </li> </ul> <p> Commissioned as quartet for the Meridian String Quartet. Sonorous, bold. Moderate difficulty. Tape available. </p> <h3>Invention for Flute and Piano</h3> <ul> <li>(1994)</li> <li> </li> <li>fl, pn</li> <li> </li> </ul> <p>3 movements</p> <h3>Little Trio</h3> <ul> <li>(1984)</li> <li>4'</li> <li>fl, guit, va</li> <li>ACA</li> </ul> <p> </p> <h3>Dr. Blood's Mermaid Lullaby</h3> <ul> <li>(1980)</li> <li>3'</li> <li>fl or ob, or vn, or vc, pn</li> <li>ACA</li> </ul> <p> </p> <h3>Trio: Dream in D</h3> <ul> <li>(1980)</li> <li>10'</li> <li>fl, pn, vc, or vn, pn, vc</li> <li> </li> </ul> <p> Rhapsodic. Passionate. Available on CD Two by Three from North/South Consonance (1998). </p> <h3>Propos II</h3> <ul> <li>(1985)</li> <li>11'</li> <li>2 tpt</li> <li> </li> </ul> <p>Arrangement from Propos</p> <h3>Rictus En Mirroir</h3> <ul> <li>(1985)</li> <li>14'</li> <li>fl, ob, hpschd, vc</li> <li> </li> </ul> <p> </p> <hr> Copyright 1999 New York Women Composers<br> Last Modified: July 28, 1999</body> </html>
I want to add something like this to the footer so readers can contact me if there's a problem with the page:
Elliotte Rusty Harold<br/> elharo@metalab.unc.edu
This information comes from the maintainer
element:
<maintainer email="elharo@metalab.unc.edu" url="http://www.macfaq.com/personal.html"> <name> <first_name>Elliotte</first_name> <middle_name>Rusty</middle_name> <last_name>Harold</last_name> </name> </maintainer>
We need a way to get content from attributes in the input document.
This is accomplished by prefixing the attribute name with @
.
<xsl:template match="catalog"> <head> <title><xsl:value-of select="category"/></title> </head> <body> <h1><xsl:value-of select="category"/></h1> <xsl:apply-templates select="composition"/> <hr/> Copyright <xsl:value-of select="copyright"/><br/> Last Modified: <xsl:value-of select="last_updated"/><br/> <xsl:apply-templates select="maintainer"/> </body> </xsl:template> <xsl:template match="maintainer"> <xsl:value-of select="name"/><br/> <xsl:value-of select="@email"/> </xsl:template>
<html> <head> <title> Small chamber ensembles - 2-4 Players by New York Women Composers </title> </head> <body> <h1> Small chamber ensembles - 2-4 Players by New York Women Composers </h1> <h3>Trio for Flute, Viola and Harp</h3> <ul> <li>(1994)</li> <li>13'38"</li> <li>fl, hp, vla</li> <li>Theodore Presser</li> </ul> <p> Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements : mvt. 1: 5:01 mvt. 2: 4:11 mvt. 3: 4:26 </p> <h3>Charmonium</h3> <ul> <li>(1991)</li> <li>9'</li> <li>2 vln, vla, vc</li> <li> </li> </ul> <p> Commissioned as quartet for the Meridian String Quartet. Sonorous, bold. Moderate difficulty. Tape available. </p> <h3>Invention for Flute and Piano</h3> <ul> <li>(1994)</li> <li> </li> <li>fl, pn</li> <li> </li> </ul> <p>3 movements</p> <h3>Little Trio</h3> <ul> <li>(1984)</li> <li>4'</li> <li>fl, guit, va</li> <li>ACA</li> </ul> <p> </p> <h3>Dr. Blood's Mermaid Lullaby</h3> <ul> <li>(1980)</li> <li>3'</li> <li>fl or ob, or vn, or vc, pn</li> <li>ACA</li> </ul> <p> </p> <h3>Trio: Dream in D</h3> <ul> <li>(1980)</li> <li>10'</li> <li>fl, pn, vc, or vn, pn, vc</li> <li> </li> </ul> <p> Rhapsodic. Passionate. Available on CD Two by Three from North/South Consonance (1998). </p> <h3>Propos II</h3> <ul> <li>(1985)</li> <li>11'</li> <li>2 tpt</li> <li> </li> </ul> <p>Arrangement from Propos</p> <h3>Rictus En Mirroir</h3> <ul> <li>(1985)</li> <li>14'</li> <li>fl, ob, hpschd, vc</li> <li> </li> </ul> <p> </p> <hr> Copyright 1999 New York Women Composers<br> Last Modified: July 28, 1999<br> Elliotte Rusty Harold <br>elharo@metalab.unc.edu</body> </html>
Add this to the footer:
<a href="http://www.macfaq.com/personal.html">Elliotte Rusty Harold</a><br/> <a href="mailto:elharo@metalab.unc.edu">elharo@metalab.unc.edu</a>
Need a way to copy nodes from the input document to attribute values in the output document.
Attribute value templates are the solution
<xsl:template match="maintainer"> <a href="{@url}"><xsl:value-of select="name"/></a><br/> <a href="mailto:{@email}"><xsl:value-of select="@email"/></a> </xsl:template>
<html> <head> <title> Small chamber ensembles - 2-4 Players by New York Women Composers </title> </head> <body> <h1> Small chamber ensembles - 2-4 Players by New York Women Composers </h1> <h3>Trio for Flute, Viola and Harp</h3> <ul> <li>(1994)</li> <li>13'38"</li> <li>fl, hp, vla</li> <li>Theodore Presser</li> </ul> <p> Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements : mvt. 1: 5:01 mvt. 2: 4:11 mvt. 3: 4:26 </p> <h3>Charmonium</h3> <ul> <li>(1991)</li> <li>9'</li> <li>2 vln, vla, vc</li> <li> </li> </ul> <p> Commissioned as quartet for the Meridian String Quartet. Sonorous, bold. Moderate difficulty. Tape available. </p> <h3>Invention for Flute and Piano</h3> <ul> <li>(1994)</li> <li> </li> <li>fl, pn</li> <li> </li> </ul> <p>3 movements</p> <h3>Little Trio</h3> <ul> <li>(1984)</li> <li>4'</li> <li>fl, guit, va</li> <li>ACA</li> </ul> <p> </p> <h3>Dr. Blood's Mermaid Lullaby</h3> <ul> <li>(1980)</li> <li>3'</li> <li>fl or ob, or vn, or vc, pn</li> <li>ACA</li> </ul> <p> </p> <h3>Trio: Dream in D</h3> <ul> <li>(1980)</li> <li>10'</li> <li>fl, pn, vc, or vn, pn, vc</li> <li> </li> </ul> <p> Rhapsodic. Passionate. Available on CD Two by Three from North/South Consonance (1998). </p> <h3>Propos II</h3> <ul> <li>(1985)</li> <li>11'</li> <li>2 tpt</li> <li> </li> </ul> <p>Arrangement from Propos</p> <h3>Rictus En Mirroir</h3> <ul> <li>(1985)</li> <li>14'</li> <li>fl, ob, hpschd, vc</li> <li> </li> </ul> <p> </p> <hr> Copyright 1999 New York Women Composers<br> Last Modified: July 28, 1999<br> <a href="http://www.macfaq.com/personal.html"> Elliotte Rusty Harold </a> <br> <a href="mailto:elharo@metalab.unc.edu">elharo@metalab.unc.edu</a> </body> </html>
The descriptions in the output document are pure text.
The descriptions in the input document are somewhat more styled and include paragraphs, unordered lists and citations; e.g.
<description> <p>Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements :</p> <ul> <li>mvt. 1: 5:01</li> <li>mvt. 2: 4:11</li> <li>mvt. 3: 4:26</li> </ul> </description>
But all this is stripped by the default template rule used for the description!
Use xsl:copy
to move these elements into
the output more or less as is:
<xsl:template match="p"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> <!-- pass HTML along unchanged --> <xsl:template match="ul"> <xsl:copy> <xsl:apply-templates"/> </xsl:copy> </xsl:template> <xsl:template match="li"> <xsl:copy> <xsl:apply-templates"/> </xsl:copy> </xsl:template> <xsl:template match="cite"> <xsl:copy> <xsl:apply-templates"/> </xsl:copy> </xsl:template>
We also have to apply templates to the description
element rather than taking its value:
<xsl:template match="composition"> <h3><xsl:value-of select="title"/></h3> <ul> <li><xsl:value-of select="date"/></li> <li><xsl:value-of select="length"/></li> <li><xsl:value-of select="instruments"/></li> <li><xsl:value-of select="publisher"/></li> </ul> <p><xsl:apply-templates select="description"/></p> </xsl:template>
<html> <head> <title> Small chamber ensembles - 2-4 Players by New York Women Composers </title> </head> <body> <h1> Small chamber ensembles - 2-4 Players by New York Women Composers </h1> <h3>Trio for Flute, Viola and Harp</h3> <ul> <li>(1994)</li> <li>13'38"</li> <li>fl, hp, vla</li> <li>Theodore Presser</li> </ul> <p> <p>Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements :</p> <ul> <li>mvt. 1: 5:01</li> <li>mvt. 2: 4:11</li> <li>mvt. 3: 4:26</li> </ul> </p> <h3>Charmonium</h3> <ul> <li>(1991)</li> <li>9'</li> <li>2 vln, vla, vc</li> <li> </li> </ul> <p> Commissioned as quartet for the Meridian String Quartet. Sonorous, bold. Moderate difficulty. Tape available. </p> <h3>Invention for Flute and Piano</h3> <ul> <li>(1994)</li> <li> </li> <li>fl, pn</li> <li> </li> </ul> <p>3 movements</p> <h3>Little Trio</h3> <ul> <li>(1984)</li> <li>4'</li> <li>fl, guit, va</li> <li>ACA</li> </ul> <p> </p> <h3>Dr. Blood's Mermaid Lullaby</h3> <ul> <li>(1980)</li> <li>3'</li> <li>fl or ob, or vn, or vc, pn</li> <li>ACA</li> </ul> <p> </p> <h3>Trio: Dream in D</h3> <ul> <li>(1980)</li> <li>10'</li> <li>fl, pn, vc, or vn, pn, vc</li> <li> </li> </ul> <p> Rhapsodic. Passionate. Available on CD <cite>Two by Three</cite> from North/South Consonance (1998). </p> <h3>Propos II</h3> <ul> <li>(1985)</li> <li>11'</li> <li>2 tpt</li> <li> </li> </ul> <p>Arrangement from Propos</p> <h3>Rictus En Mirroir</h3> <ul> <li>(1985)</li> <li>14'</li> <li>fl, ob, hpschd, vc</li> <li> </li> </ul> <p> </p> <hr> Copyright 1999 New York Women Composers<br> Last Modified: July 28, 1999<br> <a href="http://www.macfaq.com/personal.html"> Elliotte Rusty Harold </a> <br> <a href="mailto:elharo@metalab.unc.edu">elharo@metalab.unc.edu</a> </body> </html>
Since all four template rules for the HTML
element have the same content, we can combine them into a single rule
that applies to each of the four using the or operator
|
<xsl:template match="p|ul|li|cite"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template>
Right now the descriptions in the input document only use a few HTML tags, but potentially they could use full HTML up to and including tables, images, styles, and more. You could include separate template rules for each of these, but it's easier to specify a rule that applies to all elements.
<!-- pass unrecognized tags along unchanged --> <xsl:template match="*"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template>
The *
matches all elements that are not matched by some
more specific rules. It only matches element nodes, though. It does not match
nodes for
attributes
comments
processing instructions
namespaces
text
The output is the same in this case, though for a document that used more HTML it might be different.
To copy everything including:
attributes
comments
processing instructions
namespaces
text
we have to use greedier wild cards:
@* to copy attribute nodes
node()
to copy all other nodes
<!-- pass unrecognized nodes along unchanged --> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template>
xt doesn't yet recognize node()
in match patterns
The output is the same in this case, though for a document that used more HTML it might be different.
Perhaps this is too greedy. Do we really only want to recognize
HTML in the description element? What if somebody puts HTML
in a different, element like instruments
?
What if somebody makes a mistake and adds an element
that shouldn't be there?
I don't think so, but it would be possible to use modes
or other techniques to make this default rule only apply
inside the description
element.
<xsl:template match="composition"> <h3><xsl:value-of select="title"/></h3> <ul> <xsl:if test="string(date)"> <li><xsl:value-of select="date"/></li> </xsl:if> <xsl:if test="string(length)"> <li><xsl:value-of select="length"/></li> </xsl:if> <xsl:if test="string(instruments)"> <li><xsl:value-of select="instruments"/></li> </xsl:if> <xsl:if test="string(publisher)"> <li><xsl:value-of select="publisher"/></li> </xsl:if> </ul> <p><xsl:apply-templates select="description"/></p> </xsl:template>
The string()
function converts the value of the element to a string
The number()
function converts the value of the element to a number
Zero length strings are false
There are all the <
, >
, =
, !=
,
<=
and >=
operators you expect
<html> <head> <title> Small chamber ensembles - 2-4 Players by New York Women Composers </title> </head> <body> <h1> Small chamber ensembles - 2-4 Players by New York Women Composers </h1> <h3>Trio for Flute, Viola and Harp</h3> <ul> <li>(1994)</li> <li>13'38"</li> <li>fl, hp, vla</li> <li>Theodore Presser</li> </ul> <p> <description> <p>Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements :</p> <ul> <li>mvt. 1: 5:01</li> <li>mvt. 2: 4:11</li> <li>mvt. 3: 4:26</li> </ul> </description> </p> <h3>Charmonium</h3> <ul> <li>(1991)</li> <li>9'</li> <li>2 vln, vla, vc</li> </ul> <p> <description> Commissioned as quartet for the Meridian String Quartet. Sonorous, bold. Moderate difficulty. Tape available. </description> </p> <h3>Invention for Flute and Piano</h3> <ul> <li>(1994)</li> <li>fl, pn</li> </ul> <p> <description>3 movements</description> </p> <h3>Little Trio</h3> <ul> <li>(1984)</li> <li>4'</li> <li>fl, guit, va</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3>Dr. Blood's Mermaid Lullaby</h3> <ul> <li>(1980)</li> <li>3'</li> <li>fl or ob, or vn, or vc, pn</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3>Trio: Dream in D</h3> <ul> <li>(1980)</li> <li>10'</li> <li>fl, pn, vc, or vn, pn, vc</li> </ul> <p> <description> Rhapsodic. Passionate. Available on CD <cite><a href="http://www.amazon.com/exec/obidos/ASIN/B000007NMH/qid%3D913265342/sr%3D1-2/">Two by Three</a></cite> from North/South Consonance (1998). </description> </p> <h3>Propos II</h3> <ul> <li>(1985)</li> <li>11'</li> <li>2 tpt</li> </ul> <p> <description>Arrangement from Propos</description> </p> <h3>Rictus En Mirroir</h3> <ul> <li>(1985)</li> <li>14'</li> <li>fl, ob, hpschd, vc</li> </ul> <p> <description></description> </p> <hr> Copyright 1999 New York Women Composers<br> Last Modified: July 28, 1999<br> <a href="http://www.macfaq.com/personal.html"> Elliotte Rusty Harold </a> <br> <a href="mailto:elharo@metalab.unc.edu">elharo@metalab.unc.edu</a> </body> </html>
The composers and their compositions are linked through the
the id
attribute of the composer
element
and the composer
attribute of the composition
element.
<composer id="c3"> <name> <first_name>Beth</first_name> <middle_name></middle_name> <last_name>Anderson</last_name> </name> </composer> <composition composer="c3"> <title>Trio: Dream in D</title> <date><year>(1980)</year></date> <length>10'</length> <instruments>fl, pn, vc, or vn, pn, vc</instruments> <description> Rhapsodic. Passionate. Available on CD <cite><a href="http://www.amazon.com/exec/obidos/ASIN/B000007NMH/qid%3D913265342/sr%3D1-2/">Two by Three</a></cite> from North/South Consonance (1998). </description> <publisher></publisher> </composition>
<xsl:template match="catalog"> <head> <title><xsl:value-of select="category"/></title> </head> <body> <h1><xsl:value-of select="category"/></h1> <xsl:apply-templates select="composer"/> <hr/> Copyright <xsl:value-of select="copyright"/><br/> Last Modified: <xsl:value-of select="last_updated"/><br/> <xsl:apply-templates select="maintainer"/> </body> </xsl:template> <xsl:template match="composer"> <h2><xsl:value-of select="name"/></h2> <xsl:apply-templates select="../composition[@composer=current()/@id]"/> </xsl:template>
..
selects the parent element
/
selects a child of the context node
Square braces []
include a predicate to winnow down the
selected nodes
The current()
function refers to the matched composer element
@composer()
and @id
take the value of the composer
attribute and the id
attribute
The =
operator compares the to attributes
<html> <head> <title> Small chamber ensembles - 2-4 Players by New York Women Composers </title> </head> <body> <h1> Small chamber ensembles - 2-4 Players by New York Women Composers </h1> <h2> Julie Mandel </h2> <h3>Trio for Flute, Viola and Harp</h3> <ul> <li>(1994)</li> <li>13'38"</li> <li>fl, hp, vla</li> <li>Theodore Presser</li> </ul> <p> <description> <p>Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements :</p> <ul> <li>mvt. 1: 5:01</li> <li>mvt. 2: 4:11</li> <li>mvt. 3: 4:26</li> </ul> </description> </p> <h3>Invention for Flute and Piano</h3> <ul> <li>(1994)</li> <li>fl, pn</li> </ul> <p> <description>3 movements</description> </p> <h2> Margaret De Wys </h2> <h3>Charmonium</h3> <ul> <li>(1991)</li> <li>9'</li> <li>2 vln, vla, vc</li> </ul> <p> <description> Commissioned as quartet for the Meridian String Quartet. Sonorous, bold. Moderate difficulty. Tape available. </description> </p> <h2> Beth Anderson </h2> <h3>Little Trio</h3> <ul> <li>(1984)</li> <li>4'</li> <li>fl, guit, va</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3>Dr. Blood's Mermaid Lullaby</h3> <ul> <li>(1980)</li> <li>3'</li> <li>fl or ob, or vn, or vc, pn</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3>Trio: Dream in D</h3> <ul> <li>(1980)</li> <li>10'</li> <li>fl, pn, vc, or vn, pn, vc</li> </ul> <p> <description> Rhapsodic. Passionate. Available on CD <cite><a href="http://www.amazon.com/exec/obidos/ASIN/B000007NMH/qid%3D913265342/sr%3D1-2/">Two by Three</a></cite> from North/South Consonance (1998). </description> </p> <h2> Linda Bouchard </h2> <h3>Propos II</h3> <ul> <li>(1985)</li> <li>11'</li> <li>2 tpt</li> </ul> <p> <description>Arrangement from Propos</description> </p> <h3>Rictus En Mirroir</h3> <ul> <li>(1985)</li> <li>14'</li> <li>fl, ob, hpschd, vc</li> </ul> <p> <description></description> </p> <hr> Copyright 1999 New York Women Composers<br> Last Modified: July 28, 1999<br> <a href="http://www.macfaq.com/personal.html"> Elliotte Rusty Harold </a> <br> <a href="mailto:elharo@metalab.unc.edu">elharo@metalab.unc.edu</a> </body> </html>
<xsl:template match="catalog"> <head> <title><xsl:value-of select="category"/></title> </head> <body> <h1><xsl:value-of select="category"/></h1> <xsl:apply-templates select="composer"> <xsl:sort select="name/last_name"/> </xsl:apply-templates> <hr/> Copyright <xsl:value-of select="copyright"/><br/> Last Modified: <xsl:value-of select="last_updated"/><br/> <xsl:apply-templates select="maintainer"/> </body> </xsl:template>
The select
attribute provides the key to sort by
Must be a child of xsl:apply-templates
or xsl:for-each
<html> <head> <title> Small chamber ensembles - 2-4 Players by New York Women Composers </title> </head> <body> <h1> Small chamber ensembles - 2-4 Players by New York Women Composers </h1> <h2> Beth Anderson </h2> <h3>Little Trio</h3> <ul> <li>(1984)</li> <li>4'</li> <li>fl, guit, va</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3>Dr. Blood's Mermaid Lullaby</h3> <ul> <li>(1980)</li> <li>3'</li> <li>fl or ob, or vn, or vc, pn</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3>Trio: Dream in D</h3> <ul> <li>(1980)</li> <li>10'</li> <li>fl, pn, vc, or vn, pn, vc</li> </ul> <p> <description> Rhapsodic. Passionate. Available on CD <cite><a href="http://www.amazon.com/exec/obidos/ASIN/B000007NMH/qid%3D913265342/sr%3D1-2/">Two by Three</a></cite> from North/South Consonance (1998). </description> </p> <h2> Linda Bouchard </h2> <h3>Propos II</h3> <ul> <li>(1985)</li> <li>11'</li> <li>2 tpt</li> </ul> <p> <description>Arrangement from Propos</description> </p> <h3>Rictus En Mirroir</h3> <ul> <li>(1985)</li> <li>14'</li> <li>fl, ob, hpschd, vc</li> </ul> <p> <description></description> </p> <h2> Julie Mandel </h2> <h3>Trio for Flute, Viola and Harp</h3> <ul> <li>(1994)</li> <li>13'38"</li> <li>fl, hp, vla</li> <li>Theodore Presser</li> </ul> <p> <description> <p>Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements :</p> <ul> <li>mvt. 1: 5:01</li> <li>mvt. 2: 4:11</li> <li>mvt. 3: 4:26</li> </ul> </description> </p> <h3>Invention for Flute and Piano</h3> <ul> <li>(1994)</li> <li>fl, pn</li> </ul> <p> <description>3 movements</description> </p> <h2> Margaret De Wys </h2> <h3>Charmonium</h3> <ul> <li>(1991)</li> <li>9'</li> <li>2 vln, vla, vc</li> </ul> <p> <description> Commissioned as quartet for the Meridian String Quartet. Sonorous, bold. Moderate difficulty. Tape available. </description> </p> <hr> Copyright 1999 New York Women Composers<br> Last Modified: July 28, 1999<br> <a href="http://www.macfaq.com/personal.html"> Elliotte Rusty Harold </a> <br> <a href="mailto:elharo@metalab.unc.edu">elharo@metalab.unc.edu</a> </body> </html>
<xsl:template match="catalog"> <head> <title><xsl:value-of select="category"/></title> </head> <body> <h1><xsl:value-of select="category"/></h1> <xsl:apply-templates select="composer"> <xsl:sort select="name/last_name"/> <xsl:sort select="name/first_name"/> <xsl:sort select="name/middle_name"/> </xsl:apply-templates> <hr/> Copyright <xsl:value-of select="copyright"/><br/> Last Modified: <xsl:value-of select="last_updated"/><br/> <xsl:apply-templates select="maintainer"/> </body> </xsl:template>
<html> <head> <title> Small chamber ensembles - 2-4 Players by New York Women Composers </title> </head> <body> <h1> Small chamber ensembles - 2-4 Players by New York Women Composers </h1> <h2> Beth Anderson </h2> <h3>Little Trio</h3> <ul> <li>(1984)</li> <li>4'</li> <li>fl, guit, va</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3>Dr. Blood's Mermaid Lullaby</h3> <ul> <li>(1980)</li> <li>3'</li> <li>fl or ob, or vn, or vc, pn</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3>Trio: Dream in D</h3> <ul> <li>(1980)</li> <li>10'</li> <li>fl, pn, vc, or vn, pn, vc</li> </ul> <p> <description> Rhapsodic. Passionate. Available on CD <cite><a href="http://www.amazon.com/exec/obidos/ASIN/B000007NMH/qid%3D913265342/sr%3D1-2/">Two by Three</a></cite> from North/South Consonance (1998). </description> </p> <h2> Linda Bouchard </h2> <h3>Propos II</h3> <ul> <li>(1985)</li> <li>11'</li> <li>2 tpt</li> </ul> <p> <description>Arrangement from Propos</description> </p> <h3>Rictus En Mirroir</h3> <ul> <li>(1985)</li> <li>14'</li> <li>fl, ob, hpschd, vc</li> </ul> <p> <description></description> </p> <h2> Julie Mandel </h2> <h3>Trio for Flute, Viola and Harp</h3> <ul> <li>(1994)</li> <li>13'38"</li> <li>fl, hp, vla</li> <li>Theodore Presser</li> </ul> <p> <description> <p>Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements :</p> <ul> <li>mvt. 1: 5:01</li> <li>mvt. 2: 4:11</li> <li>mvt. 3: 4:26</li> </ul> </description> </p> <h3>Invention for Flute and Piano</h3> <ul> <li>(1994)</li> <li>fl, pn</li> </ul> <p> <description>3 movements</description> </p> <h2> Margaret De Wys </h2> <h3>Charmonium</h3> <ul> <li>(1991)</li> <li>9'</li> <li>2 vln, vla, vc</li> </ul> <p> <description> Commissioned as quartet for the Meridian String Quartet. Sonorous, bold. Moderate difficulty. Tape available. </description> </p> <hr> Copyright 1999 New York Women Composers<br> Last Modified: July 28, 1999<br> <a href="http://www.macfaq.com/personal.html"> Elliotte Rusty Harold </a> <br> <a href="mailto:elharo@metalab.unc.edu">elharo@metalab.unc.edu</a> </body> </html>
Sorting by composition title is equally straight-forward
but we have to do it in a separate apply-templates
element
<xsl:template match="catalog"> <head> <title><xsl:value-of select="category"/></title> </head> <body> <h1><xsl:value-of select="category"/></h1> <xsl:apply-templates select="composer"> <xsl:sort select="name/last_name"/> <xsl:sort select="name/first_name"/> <xsl:sort select="name/middle_name"/> </xsl:apply-templates> <hr/> Copyright <xsl:value-of select="copyright"/><br/> Last Modified: <xsl:value-of select="last_updated"/><br/> <xsl:apply-templates select="maintainer"/> </body> </xsl:template> <xsl:template match="composer"> <h2><xsl:value-of select="name"/></h2> <xsl:apply-templates select="../composition[@composer=current()/@id]"> <xsl:sort select="title"/> </xsl:apply-templates> </xsl:template>
<html> <head> <title> Small chamber ensembles - 2-4 Players by New York Women Composers </title> </head> <body> <h1> Small chamber ensembles - 2-4 Players by New York Women Composers </h1> <h2> Beth Anderson </h2> <h3>Dr. Blood's Mermaid Lullaby</h3> <ul> <li>(1980)</li> <li>3'</li> <li>fl or ob, or vn, or vc, pn</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3>Little Trio</h3> <ul> <li>(1984)</li> <li>4'</li> <li>fl, guit, va</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3>Trio: Dream in D</h3> <ul> <li>(1980)</li> <li>10'</li> <li>fl, pn, vc, or vn, pn, vc</li> </ul> <p> <description> Rhapsodic. Passionate. Available on CD <cite><a href="http://www.amazon.com/exec/obidos/ASIN/B000007NMH/qid%3D913265342/sr%3D1-2/">Two by Three</a></cite> from North/South Consonance (1998). </description> </p> <h2> Linda Bouchard </h2> <h3>Propos II</h3> <ul> <li>(1985)</li> <li>11'</li> <li>2 tpt</li> </ul> <p> <description>Arrangement from Propos</description> </p> <h3>Rictus En Mirroir</h3> <ul> <li>(1985)</li> <li>14'</li> <li>fl, ob, hpschd, vc</li> </ul> <p> <description></description> </p> <h2> Julie Mandel </h2> <h3>Invention for Flute and Piano</h3> <ul> <li>(1994)</li> <li>fl, pn</li> </ul> <p> <description>3 movements</description> </p> <h3>Trio for Flute, Viola and Harp</h3> <ul> <li>(1994)</li> <li>13'38"</li> <li>fl, hp, vla</li> <li>Theodore Presser</li> </ul> <p> <description> <p>Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements :</p> <ul> <li>mvt. 1: 5:01</li> <li>mvt. 2: 4:11</li> <li>mvt. 3: 4:26</li> </ul> </description> </p> <h2> Margaret De Wys </h2> <h3>Charmonium</h3> <ul> <li>(1991)</li> <li>9'</li> <li>2 vln, vla, vc</li> </ul> <p> <description> Commissioned as quartet for the Meridian String Quartet. Sonorous, bold. Moderate difficulty. Tape available. </description> </p> <hr> Copyright 1999 New York Women Composers<br> Last Modified: July 28, 1999<br> <a href="http://www.macfaq.com/personal.html"> Elliotte Rusty Harold </a> <br> <a href="mailto:elharo@metalab.unc.edu">elharo@metalab.unc.edu</a> </body> </html>
<xsl:template match="catalog"> <head> <title><xsl:value-of select="category"/></title> </head> <body> <!-- Header --> <h1><xsl:value-of select="category"/></h1> <ul> <xsl:for-each select="composition"> <li><xsl:value-of select="title"/></li> </xsl:for-each> </ul> <!-- Body --> <xsl:apply-templates select="composer"> <xsl:sort select="name/last_name"/> <xsl:sort select="name/first_name"/> <xsl:sort select="name/middle_name"/> </xsl:apply-templates> <!-- Signature --> <hr/> Copyright <xsl:value-of select="copyright"/><br/> Last Modified: <xsl:value-of select="last_updated"/><br/> <xsl:apply-templates select="maintainer"/> </body> </xsl:template>
.
selects the context node
xsl:for-each
iterates through the selected nodes,
setting each one to the current node in turn but does not
apply templates to that node.
<html> <head> <title> Small chamber ensembles - 2-4 Players by New York Women Composers </title> </head> <body> <h1> Small chamber ensembles - 2-4 Players by New York Women Composers </h1> <ul> <li>Trio for Flute, Viola and Harp</li> <li>Charmonium</li> <li>Invention for Flute and Piano</li> <li>Little Trio</li> <li>Dr. Blood's Mermaid Lullaby</li> <li>Trio: Dream in D</li> <li>Propos II</li> <li>Rictus En Mirroir</li> </ul> <h2> Beth Anderson </h2> <h3>Dr. Blood's Mermaid Lullaby</h3> <ul> <li>(1980)</li> <li>3'</li> <li>fl or ob, or vn, or vc, pn</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3>Little Trio</h3> <ul> <li>(1984)</li> <li>4'</li> <li>fl, guit, va</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3>Trio: Dream in D</h3> <ul> <li>(1980)</li> <li>10'</li> <li>fl, pn, vc, or vn, pn, vc</li> </ul> <p> <description> Rhapsodic. Passionate. Available on CD <cite><a href="http://www.amazon.com/exec/obidos/ASIN/B000007NMH/qid%3D913265342/sr%3D1-2/">Two by Three</a></cite> from North/South Consonance (1998). </description> </p> <h2> Linda Bouchard </h2> <h3>Propos II</h3> <ul> <li>(1985)</li> <li>11'</li> <li>2 tpt</li> </ul> <p> <description>Arrangement from Propos</description> </p> <h3>Rictus En Mirroir</h3> <ul> <li>(1985)</li> <li>14'</li> <li>fl, ob, hpschd, vc</li> </ul> <p> <description></description> </p> <h2> Julie Mandel </h2> <h3>Invention for Flute and Piano</h3> <ul> <li>(1994)</li> <li>fl, pn</li> </ul> <p> <description>3 movements</description> </p> <h3>Trio for Flute, Viola and Harp</h3> <ul> <li>(1994)</li> <li>13'38"</li> <li>fl, hp, vla</li> <li>Theodore Presser</li> </ul> <p> <description> <p>Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements :</p> <ul> <li>mvt. 1: 5:01</li> <li>mvt. 2: 4:11</li> <li>mvt. 3: 4:26</li> </ul> </description> </p> <h2> Margaret De Wys </h2> <h3>Charmonium</h3> <ul> <li>(1991)</li> <li>9'</li> <li>2 vln, vla, vc</li> </ul> <p> <description> Commissioned as quartet for the Meridian String Quartet. Sonorous, bold. Moderate difficulty. Tape available. </description> </p> <hr> Copyright 1999 New York Women Composers<br> Last Modified: July 28, 1999<br> <a href="http://www.macfaq.com/personal.html"> Elliotte Rusty Harold </a> <br> <a href="mailto:elharo@metalab.unc.edu">elharo@metalab.unc.edu</a> </body> </html>
xsl:for-each
can have an
xsl:sort
child just like xsl:apply-templates
<xsl:template match="catalog"> <head> <title><xsl:value-of select="category"/></title> </head> <body> <!-- Header --> <h1><xsl:value-of select="category"/></h1> <ul> <xsl:for-each select="composition"> <xsl:sort select="title"/> <li><xsl:value-of select="title"/></li> </xsl:for-each> </ul> <!-- Body --> <xsl:apply-templates select="composer"> <xsl:sort select="name/last_name"/> <xsl:sort select="name/first_name"/> <xsl:sort select="name/middle_name"/> </xsl:apply-templates> <!-- Signature --> <hr/> Copyright <xsl:value-of select="copyright"/><br/> Last Modified: <xsl:value-of select="last_updated"/><br/> <xsl:apply-templates select="maintainer"/> </body> </xsl:template>
We need to add <a name="some_name">title</a>
around each composition title so we have something to link to.
The generate-id()
function will choose a unique ID
for a particular element.
Here's the new template for the composition
<xsl:template match="composition"> <h3> <a name="{generate-id()}"> <xsl:value-of select="title"/> </a> </h3> <ul> <xsl:if test="string(date)"> <li><xsl:value-of select="date"/></li> </xsl:if> <xsl:if test="string(length)"> <li><xsl:value-of select="length"/></li> </xsl:if> <xsl:if test="string(instruments)"> <li><xsl:value-of select="instruments"/></li> </xsl:if> <xsl:if test="string(publisher)"> <li><xsl:value-of select="publisher"/></li> </xsl:if> </ul> <p><xsl:apply-templates select="description"/></p> </xsl:template>
Here's the new template for the tabel of contents link
<xsl:template match="catalog"> <head> <title><xsl:value-of select="category"/></title> </head> <body> <!-- Header --> <h1><xsl:value-of select="category"/></h1> <ul> <xsl:for-each select="composition"> <xsl:sort select="title"/> <li> <a href="#{generate-id()}"> <xsl:value-of select="title"/> </a> </li> </xsl:for-each> </ul> <!-- Body --> <xsl:apply-templates select="composer"> <xsl:sort select="name/last_name"/> <xsl:sort select="name/first_name"/> <xsl:sort select="name/middle_name"/> </xsl:apply-templates> <!-- Signature --> <hr/> Copyright <xsl:value-of select="copyright"/><br/> Last Modified: <xsl:value-of select="last_updated"/><br/> <xsl:apply-templates select="maintainer"/> </body> </xsl:template>
Although the ID is generated in two separate places, it is generated for the same node. Consequently, they are the same.
<html> <head> <title> Small chamber ensembles - 2-4 Players by New York Women Composers </title> </head> <body> <h1> Small chamber ensembles - 2-4 Players by New York Women Composers </h1> <ul> <li> <a href="#N146">Charmonium</a> </li> <li> <a href="#N211">Dr. Blood's Mermaid Lullaby</a> </li> <li> <a href="#N168">Invention for Flute and Piano</a> </li> <li> <a href="#N189">Little Trio</a> </li> <li> <a href="#N260">Propos II</a> </li> <li> <a href="#N282">Rictus En Mirroir</a> </li> <li> <a href="#N233">Trio: Dream in D</a> </li> <li> <a href="#N108">Trio for Flute, Viola and Harp</a> </li> </ul> <h2> Beth Anderson </h2> <h3> <a name="N211">Dr. Blood's Mermaid Lullaby</a> </h3> <ul> <li>(1980)</li> <li>3'</li> <li>fl or ob, or vn, or vc, pn</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3> <a name="N189">Little Trio</a> </h3> <ul> <li>(1984)</li> <li>4'</li> <li>fl, guit, va</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3> <a name="N233">Trio: Dream in D</a> </h3> <ul> <li>(1980)</li> <li>10'</li> <li>fl, pn, vc, or vn, pn, vc</li> </ul> <p> <description> Rhapsodic. Passionate. Available on CD <cite><a href="http://www.amazon.com/exec/obidos/ASIN/B000007NMH/qid%3D913265342/sr%3D1-2/">Two by Three</a></cite> from North/South Consonance (1998). </description> </p> <h2> Linda Bouchard </h2> <h3> <a name="N260">Propos II</a> </h3> <ul> <li>(1985)</li> <li>11'</li> <li>2 tpt</li> </ul> <p> <description>Arrangement from Propos</description> </p> <h3> <a name="N282">Rictus En Mirroir</a> </h3> <ul> <li>(1985)</li> <li>14'</li> <li>fl, ob, hpschd, vc</li> </ul> <p> <description></description> </p> <h2> Julie Mandel </h2> <h3> <a name="N168">Invention for Flute and Piano</a> </h3> <ul> <li>(1994)</li> <li>fl, pn</li> </ul> <p> <description>3 movements</description> </p> <h3> <a name="N108">Trio for Flute, Viola and Harp</a> </h3> <ul> <li>(1994)</li> <li>13'38"</li> <li>fl, hp, vla</li> <li>Theodore Presser</li> </ul> <p> <description> <p>Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements :</p> <ul> <li>mvt. 1: 5:01</li> <li>mvt. 2: 4:11</li> <li>mvt. 3: 4:26</li> </ul> </description> </p> <h2> Margaret De Wys </h2> <h3> <a name="N146">Charmonium</a> </h3> <ul> <li>(1991)</li> <li>9'</li> <li>2 vln, vla, vc</li> </ul> <p> <description> Commissioned as quartet for the Meridian String Quartet. Sonorous, bold. Moderate difficulty. Tape available. </description> </p> <hr> Copyright 1999 New York Women Composers<br> Last Modified: July 28, 1999<br> <a href="http://www.macfaq.com/personal.html"> Elliotte Rusty Harold </a> <br> <a href="mailto:elharo@metalab.unc.edu">elharo@metalab.unc.edu</a> </body> </html>
The xsl:number
element has a variety of attributes to determine
number style, exactly what's counted, where numbering starts, and so forth
The position()
function returns the position of the current
node in the context node list
<xsl:template match="composition"> <h3><xsl:number value="position()"/>. <a name="{generate-id()}"> <xsl:value-of select="title"/> </a> </h3> <ul> <xsl:if test="string(date)"> <li><xsl:value-of select="date"/></li> </xsl:if> <xsl:if test="string(length)"> <li><xsl:value-of select="length"/></li> </xsl:if> <xsl:if test="string(instruments)"> <li><xsl:value-of select="instruments"/></li> </xsl:if> <xsl:if test="string(publisher)"> <li><xsl:value-of select="publisher"/></li> </xsl:if> </ul> <p><xsl:apply-templates select="description"/></p> </xsl:template>
XPath has a number of basic functions for working with strings:
starts-with(main_string, prefix_string)
contains(containing_string, contained_string)
substring(string, offset, length)
substring-before(string, marker-string)
substring-after(string, marker-string)
string-length(string)
normalize(string)
translate(string, replaced_text, replacement_text)
concat(string1, string2, ...)
The strings these operate on are generally the values of nodes
These may be part of any select expression, but are most commonly used
in xsl:value-of
.
XPath does not, however, provide full Perl or POSIX regular expressions.
XSLT/XPath 2.0 might add these
substring(string, offset, length)
1 is the first character
length is optional
node sets are automatically converted to their values
<xsl:template match="composition"> <h3><xsl:number value="position()"/>. <a name="{generate-id()}"> <xsl:value-of select="title"/> </a> </h3> <ul> <xsl:if test="string(date)"> <!--not Y10K safe! --> <li><xsl:value-of select="substring(date,2,4)"/></li> </xsl:if> <xsl:if test="string(length)"> <li><xsl:value-of select="length"/></li> </xsl:if> <xsl:if test="string(instruments)"> <li><xsl:value-of select="instruments"/></li> </xsl:if> <xsl:if test="string(publisher)"> <li><xsl:value-of select="publisher"/></li> </xsl:if> </ul> <p><xsl:apply-templates select="description"/></p> </xsl:template>
<html> <head> <title> Small chamber ensembles - 2-4 Players by New York Women Composers </title> </head> <body> <h1> Small chamber ensembles - 2-4 Players by New York Women Composers </h1> <ul> <li> <a href="#N146">Charmonium</a> </li> <li> <a href="#N211">Dr. Blood's Mermaid Lullaby</a> </li> <li> <a href="#N168">Invention for Flute and Piano</a> </li> <li> <a href="#N189">Little Trio</a> </li> <li> <a href="#N260">Propos II</a> </li> <li> <a href="#N282">Rictus En Mirroir</a> </li> <li> <a href="#N233">Trio: Dream in D</a> </li> <li> <a href="#N108">Trio for Flute, Viola and Harp</a> </li> </ul> <h2> Beth Anderson </h2> <h3>1. <a name="N211">Dr. Blood's Mermaid Lullaby</a> </h3> <ul> <li>1980</li> <li>3'</li> <li>fl or ob, or vn, or vc, pn</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3>2. <a name="N189">Little Trio</a> </h3> <ul> <li>1984</li> <li>4'</li> <li>fl, guit, va</li> <li>ACA</li> </ul> <p> <description></description> </p> <h3>3. <a name="N233">Trio: Dream in D</a> </h3> <ul> <li>1980</li> <li>10'</li> <li>fl, pn, vc, or vn, pn, vc</li> </ul> <p> <description> Rhapsodic. Passionate. Available on CD <cite><a href="http://www.amazon.com/exec/obidos/ASIN/B000007NMH/qid%3D913265342/sr%3D1-2/">Two by Three</a></cite> from North/South Consonance (1998). </description> </p> <h2> Linda Bouchard </h2> <h3>1. <a name="N260">Propos II</a> </h3> <ul> <li>1985</li> <li>11'</li> <li>2 tpt</li> </ul> <p> <description>Arrangement from Propos</description> </p> <h3>2. <a name="N282">Rictus En Mirroir</a> </h3> <ul> <li>1985</li> <li>14'</li> <li>fl, ob, hpschd, vc</li> </ul> <p> <description></description> </p> <h2> Julie Mandel </h2> <h3>1. <a name="N168">Invention for Flute and Piano</a> </h3> <ul> <li>1994</li> <li>fl, pn</li> </ul> <p> <description>3 movements</description> </p> <h3>2. <a name="N108">Trio for Flute, Viola and Harp</a> </h3> <ul> <li>1994</li> <li>13'38"</li> <li>fl, hp, vla</li> <li>Theodore Presser</li> </ul> <p> <description> <p>Premiered at Queens College in April, 1996 by Sue Ann Kahn, Christine Ims, and Susan Jolles. In 3 movements :</p> <ul> <li>mvt. 1: 5:01</li> <li>mvt. 2: 4:11</li> <li>mvt. 3: 4:26</li> </ul> </description> </p> <h2> Margaret De Wys </h2> <h3>1. <a name="N146">Charmonium</a> </h3> <ul> <li>1991</li> <li>9'</li> <li>2 vln, vla, vc</li> </ul> <p> <description> Commissioned as quartet for the Meridian String Quartet. Sonorous, bold. Moderate difficulty. Tape available. </description> </p> <hr> Copyright 1999 New York Women Composers<br> Last Modified: July 28, 1999<br> <a href="http://www.macfaq.com/personal.html"> Elliotte Rusty Harold </a> <br> <a href="mailto:elharo@metalab.unc.edu">elharo@metalab.unc.edu</a> </body> </html>
XPath has several operators for doing arithmetic:
+
-
*
div
mod
These may be part of any select expression, but are most commonly used in predicates with comparison operators.
XPath includes five functions that operate on numbers:
floor(number)
returns the greatest integer smaller than the number
ceiling(number)
returns the smallest integer greater than the number
round(number)
rounds the number to the nearest integer
sum(number)
returns the sum of its arguments
format-number(number, format-string)
returns the string form of a number formatted according to the specified format-string as if by Java 1.1's
java.text.DecimalFormat
class
There are three primary ways XML documents are transformed into other formats, such as HTML, with an XSLT style sheet:
The XML document and associated style sheet are both served to the client (Web browser), which then transforms the document as specified by the style sheet and presents it to the user.
The server applies an XSL style sheet to an XML document to transform it to some other format (generally HTML) and sends the transformed document to the client (Web browser).
A third program transforms the original XML document into some other format (often HTML) before the document is placed on the server. Both server and client only deal with the post-transform document.
Place an xml-stylesheet
processing
instruction in the prolog immediately after the XML
declaration (if any) and before the document type declaration (if any).
This processing instruction should have a
type
attribute with the value
text/xml
and an href
attribute
whose value is an absolute or relative URL pointing to the style sheet.
<?xml version="1.0"?> <?xml-stylesheet type="text/xml" href="compositions.xsl"?>
Eventually application/xml+xslt
will replace text/xml
.
IE uses the non-existent MIME media type
text/xsl
instead.
This is also how you attach a CSS style sheet to a
document. The only difference here is that the
type
attribute has the value
text/xml
instead of text/css
.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <html> <xsl:apply-templates select="catalog"/> </html> </xsl:template> <xsl:template match="catalog"> <body> <xsl:apply-templates select="composition"/> </body> </xsl:template> <xsl:template match="composition"> <h3><xsl:value-of select="name"/></h3> </xsl:template> </xsl:stylesheet>
Many more ways to select and match elements including descendants, attributes, comments, processing instructions, and text.
Many more tests for predicates including basic arithmetic operations
The xsl:element
, xsl:attribute
, xsl:processing-instruction
, xsl:comment
, and xsl:text
elements can output elements, attributes, processing instructions, comments, and text calculated from data in the input document.
The xsl:copy-of
element to
copy nodes from the input to the output with their contents
intact
Parameters for passing arguments to templates
Modes for reprocessing the same element in a different fashion
Recursion
The xsl:variable
element defines named constants that can clarify your code.
Named templates, variables, and attribute sets help you reuse common template code.
The xsl:choose
and xsl:when
elements
let you select one of several possibilities depending on a condition.
The xsl:import
and xsl:include
elements merge rules from different style sheets.
Various attributes of the xsl:output
element allow you to specify the output document's format, XML declaration, document type declaration, indentation, encoding and MIME type.
Extension functions written in other languages like Java, JavaScript, and C++
Extension elements written in other languages like Java, JavaScript, and C++
A general regular expression language
Non-final variables (hence no side effects)
Loops
The Extensible Stylesheet Language (XSL) comprises two separate XML applications for transforming and formatting XML documents.
An XSL transformation applies rules to a tree read from an XML document to transform it into an output tree written as an XML document.
An XSL template rule is an xsl:template
element with a match
attribute. Nodes in the
input tree are compared against the patterns of the
match
attributes of the different template
elements. When a match is found, the contents of the
template are output.
The value of a node is a pure text (no markup) string
containing the contents of the node. This can be calculated
by the xsl:value-of
element.
The xsl:apply-templates
element continues
processing the children of the current node
The xsl:if
element produces output if, and
only if, its test
attribute is true.
The xsl:number
element inserts the number
specified by its value
attribute into the
output using a specified number format given by the
format
attribute.
The
xsl:sort
element can reorder the input nodes
before copying them to the output.
The XML Bible
Elliotte Rusty Harold
IDG Books, 1999
ISBN: 0-7645-3236-7
Chapter 14, XSLT: http://www.ibiblio.org/xml/books/bible/updates/14.html
XML in a Nutshell
Elliotte Rusty Harold and W. Scott Means
O'Reilly & Associates, 2001
ISBN 0-596-00058-8
Chapter 9 XPath: http://www.oreilly.com/catalog/xmlnut/chapter/ch09.html
This presentation: http://www.ibiblio.org/xml/slides/sd2001west/xslt
XSL Transformations 1.0 Specification: http://www.w3.org/TR/xslt/
XPath Specification: http://www.w3.org/TR/xpath