aspose file tools*
The moose likes XML and Related Technologies and the fly likes Getting my HTML output to backspace one character Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Getting my HTML output to backspace one character" Watch "Getting my HTML output to backspace one character" New topic
Author

Getting my HTML output to backspace one character

Daniel Walker
Greenhorn

Joined: Aug 09, 2001
Posts: 19
Hi there...
I am currently writing an XSL transform which will take an XML document of bibliographic entries and display them in an approximation of the Harvard reference format (ie. Walker (2000) "Polyneural Whatnot", in ANN Weekly, 3(2).)
There are up to 14 different types of bibliographic entries in the XML file, and each one needs formatting in a slightly different way. In addition, each entry can omit certain fields, and the order in which the information is stored is not necessarily the order in which it is displayed.
Take a look at these fragments of the XSL and XML:

This all works fine. However, I want to replace the final comma (,) before the '<xsl:if test="count(Note)=1">' line with a period/full stop (.) - remember here that I have no real way of knowing where I am in the results tree.
I have attempted to use the backspace character () before the '<xsl:if test="count(Note)=1">' line, but Xalan rejects this as being an invalid XML character. I can achieve the desired result with a shedload of xsl:if statements, but I would like to avoid that if possible (I am being graded on my code, you see).
I hope all of this is clear - if I am confusing anybody, let me know.
Thanks in advance for any and all replies.


------------------
daniel.walker
***i fear that i am ordinary...
...just like everyone...***


<B>daniel.walker</B><BR><I>***bleed in your own light...<BR>...dream of your own life...***</I>
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Daniel, if either Year or Month element has to be presented in input XML, you can omit "," from <xsl:choose> group and put "." after testing:
...
<xsl:choose>
<xsl:when test="count(Month)=1 and count(Year)=1">
<xsl:value-of select="Month"/> <xsl:value-of select="Year"/>
</xsl:when>
<xsl:when test="count(Month)=1 and count(Year)=0">
<xsl:value-of select="Month"/>
</xsl:when>
<xsl:when test="count(Year)=1 and count(Month)=0">
<xsl:value-of select="Year"/>
</xsl:when>
</xsl:choose>
<xsl:text>.</xsl:text>
...
What elements are required in your XML anyway?

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Daniel Walker
Greenhorn

Joined: Aug 09, 2001
Posts: 19
Unfortunately, that won't work - the only fields which are required in every entry are "Owner", "EntryType" and "Key". The data format has to be modelled on the Latex .bib format - so I am not able to change it
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Then let's direct all your output into a variable, cut everything but the last symbol and add a period:
<xsl:variable name="article">
... some output here
</xsl:variable>
<xsl:value-of select="substring ($article, 1, string-length($article))"/>.
The whole template will be:
<xsl:template match="CCI_RECORD[EntryType='Article']">
<LI><P>
<xsl:variable name="article">
<xsl:if test="count(Author)=1">
<xsl:value-of select="Author"/>,
</xsl:if>
<xsl:if test="count(Title)=1">
<B>"<xsl:value-of select="Title"/>"</B>,
</xsl:if>
<xsl:if test="count(Journal)=1">
in <I><xsl:value-of select="Journal"/></I>,
</xsl:if>
<xsl:choose>
<xsl:when test="count(Volume)=1 and count(Number)=1">
<xsl:value-of select="Volume"/>(<xsl:value-of select="Number"/> ),
</xsl:when>
<xsl:when test="count(Volume)=1 and count(Number)=0">
vol. <xsl:value-of select="Volume"/>,
</xsl:when>
<xsl:when test="count(Volume)=0 and count(Number)=1">
no. <xsl:value-of select="Number"/>,
</xsl:when>
</xsl:choose>
<xsl:if test="count(Pages)=1">
pp. <xsl:value-of select="Pages"/>,
</xsl:if>
<xsl:choose>
<xsl:when test="count(Month)=1 and count(Year)=1">
<xsl:value-of select="Month"/> <xsl:value-of select="Year"/>
</xsl:when>
<xsl:when test="count(Month)=1 and count(Year)=0">
<xsl:value-of select="Month"/>
</xsl:when>
<xsl:when test="count(Year)=1 and count(Month)=0">
<xsl:value-of select="Year"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="substring ($article, 1, string-length($article))"/>.

<xsl:if test="count(Note)=1">
<BR /><small>Note: <xsl:value-of select="Note"/></small>
</xsl:if>
<xsl:if test="count(URL)=1">
<xsl:call-template name="addURLHyperlink" />
</xsl:if>
</P></LI>
</xsl:template>
Daniel Walker
Greenhorn

Joined: Aug 09, 2001
Posts: 19
OK! Fantastic! This works perfectly (I had to modify it slightly to to get it to back up a bit before adding the period.)
I also had to use < and > entity references around my formatting tags (B & I) then disable output escaping on the <xsl:value-of> element to get it to look right.
Thanks very much for the help Mapraputa - you really do know your stuff!
[This message has been edited by Daniel Walker (edited October 29, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting my HTML output to backspace one character
 
Similar Threads
Searching XML Documents
Newbie problem with XSLT
Checking neigboring parent elements for match
NBSP in Html output
XSLT equality test