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 April 28th, 2009, 07:40 AM
Authorized User
 
Join Date: Dec 2005
Posts: 71
Thanks: 10
Thanked 0 Times in 0 Posts
Default 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)&nbsp;&nbsp;item 1 <sup>13</sup>;</li>
<li>(2)&nbsp;&nbsp;item 2 <sup>14</sup>;</li>
</ol>

Used XSL

<xsl:template match="*/list"><xsl:text>&#xA;</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.
 
Old April 28th, 2009, 08:05 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

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:
ROCXY (April 29th, 2009)
 
Old April 28th, 2009, 10:36 AM
Authorized User
 
Join Date: Jun 2006
Posts: 16
Thanks: 0
Thanked 3 Times in 3 Posts
Default 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'>&amp;nbsp;&amp;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:
ROCXY (April 29th, 2009)
 
Old April 29th, 2009, 04:13 AM
Authorized User
 
Join Date: Dec 2005
Posts: 71
Thanks: 10
Thanked 0 Times in 0 Posts
Default

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.
 
Old April 29th, 2009, 04:30 AM
Authorized User
 
Join Date: Jun 2006
Posts: 16
Thanks: 0
Thanked 3 Times in 3 Posts
Default Check this for all list types

Use this code for different type of list

1.
<xsl:number format="a"/>
for
<li>(a)&nbsp;&nbsp;item 1 <sup>13</sup>;</li>
<li>(b)&nbsp;&nbsp; item 2 <sup>14</sup>;</li>


2.
<xsl:number format="A"/>
for
<li>(A)&nbsp;&nbsp;item 1 <sup>13</sup>;</li>
<li>(B)&nbsp;&nbsp; item 2 <sup>14</sup>;</li>


3.
<xsl:number format="i"/>
for
<li>(i)&nbsp;&nbsp;item 1 <sup>13</sup>;</li>
<li>(ii)&nbsp;&nbsp; item 2 <sup>14</sup>;</li>


4.
<xsl:number format="I"/>
for
<li>(I)&nbsp;&nbsp;item 1 <sup>13</sup>;</li>
<li>(II)&nbsp;&nbsp; item 2 <sup>14</sup>;</li>


5.
<xsl:number format="01"/>
for
<li>(01)&nbsp;&nbsp;item 1 <sup>13</sup>;</li>
<li>(02)&nbsp;&nbsp; item 2 <sup>14</sup>;</li>





 
Old April 29th, 2009, 04:35 AM
Authorized User
 
Join Date: Dec 2005
Posts: 71
Thanks: 10
Thanked 0 Times in 0 Posts
Default

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.
 
Old April 29th, 2009, 04:57 AM
Authorized User
 
Join Date: Jun 2006
Posts: 16
Thanks: 0
Thanked 3 Times in 3 Posts
Default 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'>&amp;nbsp;&amp;nbsp;</xsl:text>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
The Following User Says Thank You to RICHBIRD For This Useful Post:
ROCXY (April 29th, 2009)
 
Old April 29th, 2009, 05:17 AM
Authorized User
 
Join Date: Dec 2005
Posts: 71
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Thanks a Lot Richbird
__________________
Thanks,
Rocxy.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Server did not recognize the value of HTTP Header ndr1977 .NET Web Services 0 May 23rd, 2008 01:50 PM
VB.NET: recognize errors using DTS:Package2 object dan_code SQL Server DTS 0 November 8th, 2006 06:16 AM
Recognize errors using DTS.Package2 object dan_code General .NET 0 November 8th, 2006 06:14 AM
Please help me!!!How can I recognize file types tqbinh C# 1 August 13th, 2004 09:45 AM
Doesn't recognize hard drive linuxboy Linux 0 October 31st, 2003 02:39 PM





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