Internet Professionell 3/2001, Rubrik Praxis

advertisement
Internet Professionell 3/2001, Rubrik Praxis
Listings zum XSLT-Workshop von Holger Reibold
Listing 1
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java">
<!--Other templates for transforming the rest of the XML source documents-->
<xsl:template match="date">
<xsl:variable name="year" select="string(./@year)"/>
<xsl:variable name="month" select="string(./@month)"/>
<xsl:variable name="day" select="string(./@day)"/>
<xsl:variable name="format" select="string(./@format)"/>
<xsl:variable name="formatter"
select="java:java.text.SimpleDateFormat.new($format)"/>
<xsl:variable name="date" select="java:IntDate.getDate($year, $month, $day)"/>
<p>Date:
<xsl:value-of select="java:format($formatter, $date)"/>
</p>
</xsl:template>
</xsl:stylesheet>
Listing 2
<lxslt:component prefix="counter" elements="init incr" functions="read">
<lxslt:script lang="javascript">
var counters = new Array();
function init (xslproc, elem) {
name = elem.getAttribute ("name");
value = parseInt(elem.getAttribute
("value"));
counters[name] = value;
return null;
}
function read (name) {
// Return a string.
return "" + (counters[name]);
}
function incr (xslproc, elem)
{
name = elem.getAttribute ("name");
counters[name]++;
return null;
}
</lxslt:script>
</lxslt:component>
Herunterladen