aspose file tools*
The moose likes XML and Related Technologies and the fly likes xslt output problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xslt output problem" Watch "xslt output problem" New topic
Author

xslt output problem

Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 144
Hi i'm having the below xslt code but there is a small problem.


the input xml is as below.



and the xslt is as below



when i add the bold part it is giving the output as in below screen 1 else it is giving the output as in screen 2. but i want them together. and expected output is as in screen 3.







[Thumbnail for Screen 2.JPG]


[Thumbnail for Expected.JPG]


[Thumbnail for Screen 1.JPG]

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18643
    
    8

A bigger problem is that your post is pretty much unreadable.

Your input XML has such long lines that it makes the reader have to scroll the browser window horizontally back and forth to be able to read anything.

And why are your sample outputs posted as images with tiny, unreadable text in them? Why not just post the text?

It would help a lot if you could produce a better post.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 535
    
    3
I can't read the pictures neither. The text I copy to an editor to read! It is fairly long and contains some troublesome characters that need further editing...

In any case, I can guess quite a bit what you want and what goes wrong. This is why.

In your xslt document, you have this structure. (quote but edited out irrelevance.)

<xsl:template match="chapter">
<section>
<div class="chapter">
<anchor name="BVI-CH-{@num}" />
<xsl:variable name="cnum">
<xsl:choose>
<xsl:when test="starts-with(@num,'0')">
<xsl:value-of select="substring-after(@num,'0')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@num"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="concat('Chapter ',$cnum,' ')"/>
<xsl:apply-templates/>
</div>
</section>
</xsl:template>

<xsl:template name="head" match="chapter">
<xsl:for-each select="current()/section/*">
<table class="toc-item-first-level">
<tbody>
<tr>
<td class="toc-item-number"><xsl:number format="1."></xsl:number></td>
<td class="toc-title"><xsl:value-of select="title"/><xsl:text> </xsl:text>
<anchor href="">
<xsl:value-of select="para/phrase"></xsl:value-of>
</anchor>
</td>
</tr>
</tbody>
</table>
</xsl:for-each>
</xsl:template>


You see, once you add the intended addition, you effectively produce two templates of equal priority (despite one with a name attribute).
And the lastly placed will, by design, win.

This is of course undesirable and not what you intend to produce.

The remedy (without taking care of other rendering detail) is to make the last additional part a pure named template without match attribute.
And then you call it at the appropriate place in the original template matching chapter. Like this.

This will largely produce the desired result.

ps: I have to replace a-tag by anchor to make the display possible in this forum... (This is going to be more and more painful...)
Vinod Tiwari
Ranch Hand

Joined: Feb 06, 2008
Posts: 459
    
    1
Please format your post, its really unreadable.


Vinod Tiwari | Twitter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xslt output problem