• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xslt output problem

 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.




Screen 2.JPG
[Thumbnail for Screen 2.JPG]
Screen 2
Expected.JPG
[Thumbnail for Expected.JPG]
Expected
Screen 1.JPG
[Thumbnail for Screen 1.JPG]
Screen 1
 
Paul Clapham
Sheriff
Posts: 21002
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 656
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 466
1
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please format your post, its really unreadable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic