Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > minor JAXP annoyance

Reply
Thread Tools

minor JAXP annoyance

 
 
Bloody Viking
Guest
Posts: n/a
 
      12-16-2004
I've got an XSLT stylesheet which I've written and maintained for over
2 years now. I've always simply processed it with java
org.apache.xalan.xslt.Process, but now I'm trying to speed things up,
by compiling the stylesheet once, and processing hundreds of XML docs
with it. The output is HTML.

This is Java 1.4.1 on a Sparc9.

The relevant code:
in main():
TransformerFactory tFactory = TransformerFactory.newInstance();
translet = tFactory.newTemplates(new StreamSource(xslInURI));

and then, in a method:

Transformer transformer = translet.newTransformer();
transformer.setParameter("baseurl", baseurlParam);
transformer.setParameter("directory", dirParam);
transformer.setParameter("imageurl", imageParam);
transformer.transform(new StreamSource(xmlInURI),
new StreamResult(new
FileOutputStream(htmlOutURI)));

The problem is, unlike when using Process, the following bit of XSLT
inserts a newline between the </img> and the </a>, which causes the
HTML to display an undesirable underscore after cite.gif (which is a
small paragraph symbol the user is expected to click to invoke the
javascript).

In the source for this stylesheet, all the text within the <xsl:if> is
on a single line of nearly 700 characters.

<xsl:if test="@seqNum">
<a><xsl:attribute
name="href">javascript:showCitation(&apos;<xsl:val ue-of
select="$citableAuthors"/>&apos;,&apos;<xsl:value-of
select="$citableTitle"/>&apos;,&apos;<xsl:value-of
select="$journalName"/>&apos;,&apos;<xsl:value-of
select="$volume"/>&apos;,&apos;<xsl:value-of
select="$pages"/>&apos;,&apos;<xsl:value-of
select="$citableSectionTitle"/>&apos;,&apos;<xsl:value-of
select="@seqNum"/>&apos</xsl:attribute><img border="0"><xsl:attribute
name="src">/images/cite.gif</xsl:attribute><xsl:attribute
name="alt"><xsl:value-of select="$citableAuthors"/> S-<xsl:value-of
select="ancestor::*...@sectNum"/> #<xsl:value-of
select="@seqNum"/></xsl:attribute></img></a>
</xsl:if>

- Paul M Lieberman
American Psychological Association

 
Reply With Quote
 
 
 
 
Joris Gillis
Guest
Posts: n/a
 
      12-16-2004
> The problem is, unlike when using Process, the following bit of XSLT
> inserts a newline between the </img> and the </a>, which causes the
> HTML to display an undesirable underscore after cite.gif (which is a
> small paragraph symbol the user is expected to click to invoke the
> javascript).
>
> In the source for this stylesheet, all the text within the <xsl:if> is
> on a single line of nearly 700 characters.


I dont't know if this will solve your problem, but I think it's not a good habit to make single line code of 700 characters. Or maybe it's just a matter of taste?

You could use the 'xsl:text' element to prohibit line breaks inside the href attribute:

<xsl:if test="@seqNum">
<a>
<xsl:attribute name="href">
<xsl:text>javascript:showCitation('</xsl:text>
<xsl:value-of select="$citableAuthors"/>
<xsl:text>','</xsl:text>
<xsl:value-of select="$citableTitle"/>
<xsl:text>','</xsl:text>
<xsl:value-of select="$journalName"/>
<xsl:text>','</xsl:text>
<xsl:value-of select="$volume"/>
<xsl:text>','</xsl:text>
<xsl:value-of select="$pages"/>
<xsl:text>','</xsl:text>
<xsl:value-of select="$citableSectionTitle"/>
<xsl:text>','</xsl:text>
<xsl:value-of select="@seqNum"/>
<xsl:text>')</xsl:text>
</xsl:attribute>
<img border="0">
<xsl:attribute name="src">
<xsl:text>/images/cite.gif</xsl:text>
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="$citableAuthors"/>
<xsl:text> S-</xsl:text>
<xsl:value-of select="ancestor::*...@sectNum"/>
<xsl:text> #</xsl:text>
<xsl:value-of select="@seqNum"/>
</xsl:attribute>
</img>
</a>
</xsl:if>


You can do that automatically by applying a stylesheet like this to your stylesheet

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform" xmlns:nxsl="new.xml">

<xsl:namespace-alias stylesheet-prefix="nxsl" result-prefix="xsl"/>
<xslutput method="xml" omit-xml-declaration="yes" indent="yes"/>

<xsl:template match="/">
<nxsl:newxslt>
<xsl:apply-templates/>
</nxsl:newxslt>
</xsl:template>

<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

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

</xsl:stylesheet>


regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Spread the wiki (http://en.wikipedia.org)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Minor XP annoyance Homer J. Simpson Windows 64bit 4 07-22-2007 08:16 PM
Minor annoyance with Thunderbird History Fan Firefox 7 05-06-2007 11:04 AM
Minor Windows annoyance when starting up and shutting down Hungerdunger Computer Support 4 04-19-2006 08:19 PM
minor JAXP annoyance paulmlieberman@alum.mit.edu Java 0 12-15-2004 10:12 PM
LCD smudging minor annoyance Jeff Durham Digital Photography 3 06-14-2004 05:53 PM



Advertisments