This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Trouble With Multiple File Outputs Based on Letter
- From: "PHP User" <phpuser at chek dot com>
- To: XSL-List at lists dot mulberrytech dot com
- Date: 16 May 2002 15:08:31 -0000
- Subject: [xsl] Trouble With Multiple File Outputs Based on Letter
- Reply-to: xsl-list at lists dot mulberrytech dot com
Sorry if you're seeing this twice, first attempt seems to have vanished.
I have a large XML Doc with a tree something like this:
<ead>
<archdesc>
<dsc>
<co1>
<did>
<unittile>
<title>
<c02>
<did>
<unittitle>
<title>
I am trying to break this rather large doc up into multiple files based on letters of the alphabet. Each new file (a.html, b.html, c.html, etc...) will have the contents of the <title></title> if that <title> starts with the same letter that the file has as it's name. e.g. a.html has the <title>A Stitch in Time</title>
The style sheet below will happily create the files for each letter, but only puts the first A <title> it comes to into each one of the files. So it's just finding a title that begins with the letter A and it then just stops, rather than putting ALL the title's that start with A into a.html, and then all the B's into b.html and so on.
I'm totally stuck, not sure what I am doing wrong, or how to proceed.
Currently I am running it through XT, but that's not a necessity, so I can switch processors.
Thanks!
=========
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xt="http://www.jclark.com/xt"
extension-element-prefixes="xt">
<xsl:template match="/">
<xsl:call-template name="out" />
</xsl:template>
<xsl:template name="out">
<html>
<head><title>Title</title></head>
<body>
<!-- this is just a list of letters to get something to loop through -->
<xsl:for-each select="/ead/archdesc/other/letter">
<xsl:variable name="file" select="." />
<xt:document method="html" href="{$file}.html">
<xsl:call-template name="page">
<xsl:value-of select="$sTitle" />
</xsl:call-template>
</xt:document>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template name="page">
<html>
<head><title>The Letter <xsl:value-of select="." /></title></head>
<body>
<xsl:for-each select=".">
<!--var decl -->
<xsl:variable name="lett" select="."/>
<xsl:variable name="initTitle" select="substring(//did/unittitle/title,'1','1')" />
<xsl:variable name="lett_case_mod" select="translate($lett,'abcdef','ABCDEF')" />
<xsl:variable name="Title" select="//did/unittitle/title" />
<!--param decl -->
<xsl:param name="lett" select="$lett" />
<xsl:param name="sTitle" select="$Title" />
<h1><xsl:value-of select="$sTitle" /></h1>
<xsl:if test="$lett_case_mod = $initTitle">
<xsl:call-template name="showbox"/>
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template name="showbox">
Show That Box Here!
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list