• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

xslt output problem

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 26750
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 733
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...)
 
Ranch Hand
Posts: 466
1
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please format your post, its really unreadable.
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic