 |
| 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
|
|
|
|

April 28th, 2009, 07:40 AM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 71
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Using of correct XPATH to recognize arributes
Hi All,
Here below is an help request to recognize attributes @type @before @after
Input XML
<p><text>para goes here â¦â¦â¦â¦â¦.
<list type="arabic" before="(" after=")">
<li><p><text>item 1 <footref id="13"/>;</text></p></li><li><p><text> item 2 <footref id="14"/>;</text></p></li>
</list>
</p>
Required XML
<ol>
<li>(1) item 1 <sup>13</sup>;</li>
<li>(2) item 2 <sup>14</sup>;</li>
</ol>
Used XSL
<xsl:template match="*/list"><xsl:text>
</xsl:text><xsl:element name="list"><xsl:attribute name="type">1</xsl:attribute><xsl:value-of select="."/></xsl:element></xsl:template>
Any Help would be grateful.
__________________
Thanks,
Rocxy.
|
|

April 28th, 2009, 08:05 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Assuming you want to transform
Code:
<list type="arabic" before="(" after=")">
<li><p><text>item 1 <footref id="13"/>;</text></p></li><li><p><text> item 2 <footref id="14"/>;</text></p></li>
</list>
to
Code:
<ol>
<li>(1) item 1 <sup>13</sup>;</li>
<li>(2) item 2 <sup>14</sup>;</li>
</ol>
then the following stylesheet does that:
Code:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="list">
<ol>
<xsl:apply-templates/>
</ol>
</xsl:template>
<xsl:template match="li">
<xsl:copy>
<xsl:value-of select="../@before"/>
<xsl:number/>
<xsl:value-of select="../@after"/>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="footref">
<sup>
<xsl:value-of select="@id"/>
</sup>
</xsl:template>
</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|
The Following User Says Thank You to Martin Honnen For This Useful Post:
|
|
|

April 28th, 2009, 10:36 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 16
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Please look into this
Use This Code:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="title">
<xsl:element name="title"><xsl:apply-templates/></xsl:element>
</xsl:template>
<xsl:template match="list">
<xsl:variable name="listyp"><xsl:value-of select="@type"/></xsl:variable>
<xsl:choose>
<xsl:when test="$listyp='arabic'">
<xsl:element name="ol"><xsl:apply-templates/></xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="li">
<xsl:variable name="lisbf" select="../@before"/>
<xsl:variable name="lisaf" select="../@after"/>
<xsl:element name="li">
<xsl:value-of select="$lisbf"/><xsl:number/><xsl:value-of select="$lisaf"/>
<xsl:text disable-output-escaping ='yes'>&nbsp;&nbsp;</xsl:text>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="footref">
<xsl:element name="sup">
<xsl:value-of select="@id"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Last edited by RICHBIRD; April 28th, 2009 at 10:52 AM..
|
|
The Following User Says Thank You to RICHBIRD For This Useful Post:
|
|
|

April 29th, 2009, 04:13 AM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 71
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Thanks a lot Honnen and Richbird, It is very use full! Similarly How do I update XSLT when I come across other list type lilke (alpha, roman etc.,) Kindly advice Let us assume following exhibits.
Input Code:
<list type="arabic" before="(" after=")">
<li><p><text>item 1</text></p></li>
<li><p><text>item 2</text></p>
<list type="alpha" before="[" after="]">
<li><p><text>Sub item 1</text></p></li>
<li><p><text>Sub item 2</text></p></li>
</list>
</li>
</list>
Required Output:
<ol>
<li>(1) item 1 </li>
<li>(2) item 2
<ol>
<li>(a)Sub item 1</li>
<li>(b)Sub item 2</li>
</ol>
</li>
</ol>
Thanks once again! For your promt response.
__________________
Thanks,
Rocxy.
|
|

April 29th, 2009, 04:30 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 16
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Check this for all list types
Use this code for different type of list
1.
<xsl:number format="a"/>
for
<li>(a) item 1 <sup>13</sup>;</li>
<li>(b) item 2 <sup>14</sup>;</li>
2.
<xsl:number format="A"/>
for
<li>(A) item 1 <sup>13</sup>;</li>
<li>(B) item 2 <sup>14</sup>;</li>
3.
<xsl:number format="i"/>
for
<li>(i) item 1 <sup>13</sup>;</li>
<li>(ii) item 2 <sup>14</sup>;</li>
4.
<xsl:number format="I"/>
for
<li>(I) item 1 <sup>13</sup>;</li>
<li>(II) item 2 <sup>14</sup>;</li>
5.
<xsl:number format="01"/>
for
<li>(01) item 1 <sup>13</sup>;</li>
<li>(02) item 2 <sup>14</sup>;</li>
|
|

April 29th, 2009, 04:35 AM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 71
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Thanks Richbird.
How that can be checked using <xsl:when> when both(arabic and alpha) comes together! has shown above in the exhibit???? - Please check and advice,.
__________________
Thanks,
Rocxy.
|
|

April 29th, 2009, 04:57 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 16
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
It will help u in this case
<xsl:template match="li">
<xsl:variable name="listype" select="../@type"/>
<xsl:variable name="lisbf" select="../@before"/>
<xsl:variable name="lisaf" select="../@after"/>
<xsl:element name="li"><xsl:value-of select="$lisbf"/>
<xsl:choose>
<xsl:when test="$listype='arabic'">
<xsl:number format="1"/>
</xsl:when>
<xsl:when test="$listype='alpha'">
<xsl:number format="a"/>
</xsl:when>
<xsl:otherwise>
<xsl:number/>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$lisaf"/>
<xsl:text disable-output-escaping ='yes'>&nbsp;&nbsp;</xsl:text>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
|
|
The Following User Says Thank You to RICHBIRD For This Useful Post:
|
|
|

April 29th, 2009, 05:17 AM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 71
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Thanks a Lot Richbird
__________________
Thanks,
Rocxy.
|
|
 |