Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 3rd, 2011, 08:16 AM
Authorized User
 
Join Date: Nov 2010
Posts: 50
Thanks: 0
Thanked 1 Time in 1 Post
Default emphasis

i need transformation from xml to html by using xslt. i have problem with transformation and i have pasted xml and xsl coding below. kindly look it and give solution for this.

xml coding:

<p>the sample test <span style="font-style: bold;">sdgvdfgdf</span> <span style="font-style: italic;">sdgvdfgdf</span> <span style="text-decoration: underline;">ou</span> end text</p>


xsl Coding:

<xsl:template match="*/span">
<xsl:choose>
<xsl:when test="@style='font-style: italic'">
<i><xsl:apply-templates/></i>
</xsl:when>
<xsl:when test="@style='font-style: text-decoration: underline'">
<b><xsl:apply-templates/></b>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

Kindly look at this. whether the xsl coding is incorrect give correct solution for us.

Thanks
Rockbal
 
Old June 3rd, 2011, 08:24 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well I would move to templates e.g.
Code:
<xsl:template match="span[@style = 'font-style: italic']">
  <i>
    <xsl:apply-templates/>
  </i>
</xsl:template>

<xsl:template match="span[@style = 'font-style: bold']">
  <b>
    <xsl:apply-templates/>
  </b>
</xsl:template>

<xsl:template match="span[@style = 'text-decoration: underline']">
  <b>
    <xsl:apply-templates/>
  </b>
</xsl:template>
The major problem of course is dealing with an input format that allows combining styles in the 'style' attribute e.g. if you have input with
Code:
<span style="text-decoration: underline; font-weight: bold;">...</span>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old June 4th, 2011, 12:38 AM
Authorized User
 
Join Date: Nov 2010
Posts: 50
Thanks: 0
Thanked 1 Time in 1 Post
Default empahsis

i use your coding but not convert the emphasis style and the style attribute hold single attribute value only.

Kindly give us solution.
Thanks
rockbal
 
Old June 4th, 2011, 07:57 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I think I overlooked the trailing semicolons so try
Code:
<xsl:template match="span[@style = 'font-style: italic;']">
  <i>
    <xsl:apply-templates/>
  </i>
</xsl:template>

<xsl:template match="span[@style = 'font-style: bold;']">
  <b>
    <xsl:apply-templates/>
  </b>
</xsl:template>
If you still have problems applying that suggestion then consider to post a sample of the XML input you have and the corresponding output you want to create with XSLT. And please make use of http://p2p.wrox.com/misc.php?do=bbcode#code to mark up code samples.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.