Re: The XSL-List Digest V3 #86

Subject: Re: The XSL-List Digest V3 #86
From: Perry Roland <pdr4h@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 27 Jun 2000 14:20:38 -0400
Hi,

I'm attempting to transform one XML file into another.  The only
modification I want to make is to add IDs to div elements.  That part
works correctly; however, I'm having trouble processing comments.  I'm
probably missing something very elementary and that's probably why I'm
having such a hard time seeing what's wrong.  I'm using saxon.

As you can see, I'm not getting comments in the output.

If this proves too easy, I have another question, too.  Elements without
content, given in the XML source file as "<head></head>", show up in the
output as self-terminating, e.g. "<head/>".  Is there a way to force
saxon to output both start and end tags?

--
perry

------------------------------ CUT HERE ------------------------------
My XML file (abbreviated):
-------------------------
<?xml version="1.0"?>
<TEI.2 id="AlgJoeh"> 
<teiHeader> 
<fileDesc> 
<titleStmt> 
<title>Joe the Hotel Boy, or Winning Out by Pluck [a machine-readable transcription] 
</title>  
<author>Alger, Horatio, 1832-1899</author>  
</titleStmt>  
<notesStmt> 
<note>Illustrations have been included from the print version.  
</note>  
<note>Split contractions are marked with a "+".</note> 
</notesStmt>  
<sourceDesc> 
<biblFull> 
<titleStmt> 
<title>Joe the Hotel Boy, or Winning Out By Pluck 
</title>  

<author>Horatio Alger
</author>  
<respStmt> 
<resp> 
</resp>  
<name> 
</name>  
</respStmt>  
</titleStmt>  
<editionStmt> 
<p>1st Edition 
</p>  
</editionStmt>  
<extent>268 pages. 
</extent>  
<publicationStmt> 
<publisher>Cupples &amp; Leon Co. 
</publisher>  
<pubPlace>New York 
</pubPlace>  
<date>1906 
</date>  
</publicationStmt>  
</biblFull>  
</sourceDesc>  
</fileDesc>  
<encodingDesc> 
<editorialDecl> 
<p>All quotation marks retained as data. 
</p>  
<p>Spell-check and verification made against printed text using WordPerfect spell checker. 
</p>  
<p>All unambiguous end-of-line hyphens have been removed, and thetrailing part of a word has been joined to the preceding line. 
</p>  
<p>The images exist as archived TIFF images, one or more JPEG versionsfor general use, and thumbnail GIFs. 
</p>  
<p>Keywords in the header are a local Electronic Text Center scheme to aid in establishing analytical groupings. 
</p>  
</editorialDecl>  
</encodingDesc>  
<profileDesc> 
<creation> 
<date>1906 
</date>  
</creation>  
<langUsage> 
<language id="eng">English 
</language>  
</langUsage>  
</profileDesc>  
</teiHeader>  
 
<text id="AlgJoehT">  
<front> 
<div type="frontis" id="dummyid"> 
<head></head>
<p> 
<figure entity="AlgJoFr"> 
<head>HE HALF DRAGGED AND HALF CARRIED THE UNCONSCIOUS LADY TO 
THE NEAREST STAIRCASE.--Page 202.</head> 
<figDesc>Illustration by Nuttall. Joe, the Hotel Boy, at the top of a 
staircase in a burning building holding an unconscious woman in his 
arms.</figDesc> 
</figure> 
</p> 
</div> 
 
<titlePage> 
<titlePart type="main"> 
JOE THE HOTEL BOY <lb/>
OR <lb/>
WINNING OUT BY PLUCK</titlePart> 
 
<byline> 
BY HORATIO ALGER, JR. <lb/> 
AUTHOR OF ``RAGGED DICK,'' ``TATTERED TOM,'' ``NELSON 
THE NEWSBOY,'' ``OUT FOR BUSINESS'' ETC.</byline> 
 
<docImprint> 
ILLUSTRATED 
<lb/> 
NEW YORK 
CUPPLES &amp; LEON CO. 
 
<lb/> 
<hi>Copyright, 1906,</hi><lb/><!-- added linebreak 5/15/2000 PR -->
BY CUPPLES &amp; LEON.<lb/><!-- added linebreak 5/15/2000 PR -->
 
JOE THE HOTEL BOY. 
</docImprint> 
</titlePage> 
 
<div type="contents"> 
<head></head>CONTENTS PAGE HERE
</div> 
</front> 
 <pb n="1"/>
<body> 
<head>JOE THE HOTEL BOY.</head>  

<div0 type="chapter" n="1"> 
<head>CHAPTER I.<lb/> 
OUT IN A STORM.</head> 
 
<p>``WHAT do you think of this storm, Joe?'' 
</p><p>``I think it is going to be a heavy one, Ned. 
I wish we were back home,'' replied Joe 
Bodley, as he looked at the heavy clouds which 
overhung Lake Tandy. 
</p>

<p>THE END.</p> 
   
</div0>
</body> 
 
</text> 
</TEI.2> 
 

My XSL file:
-----------
<!DOCTYPE stylesheet [
]>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml"/>

<xsl:template match="*|@*|processing-instruction()|text()">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="comment()">
	<xsl:comment><xsl:value-of select="."/></xsl:comment>
</xsl:template>

<xsl:template match="div|div0|div1|div2|div3|div4|div5|div6|div7|div8|div9|titlePage">
	<xsl:variable name="elementname" select="local-name()"/>
	<xsl:element name="{$elementname}">
		<xsl:copy-of select="@*"/>
		<xsl:if test="not(@id)">
			<xsl:attribute name="id"><xsl:value-of select="generate-id()"/></xsl:attribute>
		<xsl:comment> ADDED ID </xsl:comment>
		</xsl:if>
		<xsl:apply-templates/>
	</xsl:element>
</xsl:template>

</xsl:stylesheet>


The output:
----------
<?xml version="1.0" encoding="utf-8" ?><TEI.2 id="AlgJoeh"> 
<teiHeader> 
HEADER STUFF IN HERE
</teiHeader>  
 
<text id="AlgJoehT">  
<front> 
<div type="frontis" id="dummyid"> 
<head/>
<p> 
<figure entity="AlgJoFr"> 
<head>HE HALF DRAGGED AND HALF CARRIED THE UNCONSCIOUS LADY TO 
THE NEAREST STAIRCASE.--Page 202.</head> 
<figDesc>Illustration by Nuttall. Joe, the Hotel Boy, at the top of a 
staircase in a burning building holding an unconscious woman in his 
arms.</figDesc> 
</figure> 
</p> 
</div> 
 
<titlePage id="b2ab3b1b3"><!-- ADDED ID --> 
<titlePart type="main"> 
JOE THE HOTEL BOY <lb/>
OR <lb/>
WINNING OUT BY PLUCK</titlePart> 
 
<byline> 
BY HORATIO ALGER, JR. <lb/> 
AUTHOR OF ``RAGGED DICK,'' ``TATTERED TOM,'' ``NELSON 
THE NEWSBOY,'' ``OUT FOR BUSINESS'' ETC.</byline> 
 
<docImprint> 
ILLUSTRATED 
<lb/> 
NEW YORK 
CUPPLES &amp; LEON CO. 
 
<lb/> 
<hi>Copyright, 1906,</hi><lb/>
BY CUPPLES &amp; LEON.<lb/>
 
JOE THE HOTEL BOY. 
</docImprint> 
</titlePage> 
 
<div type="contents" id="b2ab3b1b5"><!-- ADDED ID --> 
<head/> CONTENTS PAGE HERE
</div> 
</front> 
 <pb n="1"/>
<body> 
<head>JOE THE HOTEL BOY.</head>  

<div0 type="chapter" n="1" id="b2ab3b5b3"><!-- ADDED ID --> 
<head>CHAPTER I.<lb/> 
OUT IN A STORM.</head> 
 
<p>``WHAT do you think of this storm, Joe?'' 
</p><p>``I think it is going to be a heavy one, Ned. 
I wish we were back home,'' replied Joe 
Bodley, as he looked at the heavy clouds which 
overhung Lake Tandy. 
</p>

<p>THE END.</p> 
   
</div0>
</body> 
 
</text> 
</TEI.2>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread