Subject: Re: [xsl] Can this hard-coded template be generalized? From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Sun, 02 Oct 2011 16:37:45 -0400 |
Below are two abbreviated but complete files.
They produce the HTML output I want, but only by hard coding my XSLT stylesheet (the code in question is in <xsl:template name="page">). The stylesheet writes to the working directory.
Note that I have hardcoded the numbers 105, 106, 107, and 108 from the data (the XML file is below the stylesheet.
Either the data is too impoverished for me to accomplish my end, or I am too inexperienced at XPath to generalize the code.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cps="http://www.cpslib.org" exclude-result-prefixes="xs cps" version="2.0">
<xsl:template match="Stamp"> <xsl:result-document href="{../@year}-{CatNumbers/@pofis-number}.htm"> <html> <head/> <body> <a lang="en" class="button" href="{Formats/@complex}s.htm">Se-tenant</a> <a lang="cz" class="button" href="{Formats/@complex}s.htm">Spojky</a> </body> </html> </xsl:result-document> </xsl:template>
Thanks, Mark -----------------------
The XSLT stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cps="http://www.cpslib.org" exclude-result-prefixes="xs cps" version="2.0">
<xsl:template match="Set">
<xsl:apply-templates>
<xsl:with-param name="page-name-stem" tunnel="yes" select="concat(@year, '-')"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Stamp"> <!-- Write out the stamp page --> <xsl:variable name="base-number" select="CatNumbers/@pofis-number"/> <xsl:call-template name="page"> <xsl:with-param name="file-type" select="concat($base-number, '.htm')"/> </xsl:call-template> </xsl:template>
<xsl:template name="page">
<xsl:param name="file-type"/>
<xsl:param name="page-name-stem" tunnel="yes"/>
<xsl:result-document href="{concat($page-name-stem, $file-type)}">
<html>
<head/>
<body>
<xsl:for-each-group select="../Stamp/Formats" group-by="@complex">
<xsl:variable name="file-name" select="concat(@complex, 's.htm')"/>
<!-- Hardcode starts here -->
<xsl:if test="@complex eq '105' and (cps:extract-number($file-type) eq '105' or cps:extract-number($file-type) eq '106')">
<a lang="en" class="button" href="{$file-name}">Se-tenant</a>
<a lang="cz" class="button" href="{$file-name}">Spojky</a>
</xsl:if>
<xsl:if test="@complex eq '107' and (cps:extract-number($file-type) eq '107' or cps:extract-number($file-type) eq '108')">
<a lang="en" class="button" href="{$file-name}">Se-tenant</a>
<a lang="cz" class="button" href="{$file-name}">Spojky</a>
</xsl:if>
</xsl:for-each-group>
</body>
</html>
</xsl:result-document>
</xsl:template>
<xsl:function name="cps:extract-number"> <xsl:param name="data"/> <xsl:value-of select="replace($data, '\P{N}', '')"/> </xsl:function> </xsl:stylesheet>
------------------------------ The XML:
<?xml version="1.0" encoding="UTF-8"?>
<Set domain="cr" year="1996" month="3" day="27"> <Stamp> <CatNumbers pofis-number="105"/> <Formats souvenir-sheet="105"/> <Formats complex="105"/> </Stamp> <Stamp> <CatNumbers pofis-number="106"/> <Formats souvenir-sheet="105"/> <Formats complex="105"/> </Stamp> <Stamp> <CatNumbers pofis-number="107"/> <Formats souvenir-sheet="105"/> <Formats complex="107" /> </Stamp> <Stamp> <CatNumbers pofis-number="108"/> <Formats souvenir-sheet="105"/> <Formats complex="107" /> </Stamp> </Set>
-- Contact us for world-wide XML consulting and instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Can this hard-coded template , Mark | Thread | Re: [xsl] Can this hard-coded templ, Mark |
[xsl] Can this hard-coded template , Mark | Date | Re: [xsl] Can this hard-coded templ, Mark |
Month |