Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 21st, 2009, 10:57 AM
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Add commos after the element

Hello,

I'm newbie to XSLT, I have a task is based on xml file convert in to another xml with the same codings based on input xml. But in some of the element after the tag need to add puntuation i.e dot, commos etc..

How to write the xslt for this task.. Any one please help me...

Thanks and Regards,
Nagaraj
Reply With Quote
  #2 (permalink)  
Old April 21st, 2009, 11:00 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Consider to post a representative sample of your XML input and the corresponding output you want your stylesheet to create.
And let us know whether you want to use XSLT 2.0 or 1.0.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
  #3 (permalink)  
Old April 21st, 2009, 11:16 AM
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I here attached with the Sample xml file, I need to copy all the element with attributes, but after the element <ce:label>[1]</ce:label> to add the , and . somethings i.e <ce:label>[1]</ce:label>,


<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="Sample.xsl" type="text/xsl"?>
<chapter version="5.1" docsubtype="chp" id="c0001" xml:lang="en" xmlns="http://www.elsevier.com/xml/ehs-book/dtd" xmlns:sb="http://www.elsevier.com/xml/common/dtd" xmlns:ce="http://www.elsevier.com/xml/common/dtd" xmlns:xlink="http://www.w3.org/1999/xlink">
<info>
<ce:pii>
</ce:pii>
<ce:isbn>
</ce:isbn>
<ce:copyright type="full-transfer" year="2008">Elsevier Inc.</ce:copyright>
</info>
<ce:label/>
<ce:title/>
<ce:sections>
<ce:para/>
</ce:sections>
<ce:bibliography id="biblio001">
<ce:section-title id="st0010">Vancouver style (Styles 3 (numbered) and 4 (name-date)):</ce:section-title>
<ce:bibliography-sec id="bibl001">
<ce:bib-reference id="bib001">
<ce:label>[1]</ce:label>
<sb:reference id="ref001">
<sb:contribution>
<sb:authors>
<sb:author>
<ce:surname>Paivio</ce:surname>
<ce:given-name>A</ce:given-name>
</sb:author>
<sb:author>
<ce:surname>Jansen</ce:surname>
<ce:given-name>B</ce:given-name>
</sb:author>
<sb:author>
<ce:surname>Becker</ce:surname>
<ce:given-name>LJ</ce:given-name>
</sb:author>
</sb:authors>
<sb:title>
<sb:maintitle>Comparisons through the mind&apos;s eye</sb:maintitle>
</sb:title>
</sb:contribution>
<sb:host>
<sb:issue>
<sb:series>
<sb:title>
<sb:maintitle>Cognition</sb:maintitle>
</sb:title>
<sb:volume-nr>37</sb:volume-nr>
</sb:series>
<sb:issue-nr>2</sb:issue-nr>
<sb:date>1975</sb:date>
</sb:issue>
<sb:pages>
<sb:first-page>635</sb:first-page>
<sb:last-page>647</sb:last-page>
</sb:pages>
</sb:host>
</sb:reference>
</ce:bib-reference>
<ce:bib-reference id="bib002">
<ce:label>[2]</ce:label>
<sb:reference id="ref002">
<sb:contribution>
<sb:authors>
<sb:author>
<ce:surname>Yuen</ce:surname>
<ce:given-name>AWC</ce:given-name>
</sb:author>
</sb:authors>
<sb:title>
<sb:maintitle>Lamotrigine: a review of antiepileptic efficacy</sb:maintitle>
</sb:title>
</sb:contribution>
<sb:host>
<sb:issue>
<sb:series>
<sb:title>
<sb:maintitle>Epilepsia</sb:maintitle>
</sb:title>
<sb:volume-nr>35</sb:volume-nr>
</sb:series>
<sb:issue-nr>Suppl. 5</sb:issue-nr>
<sb:date>1994</sb:date>
</sb:issue>
<sb:pages>
<sb:first-page>S33</sb:first-page>
<sb:last-page>S36</sb:last-page>
</sb:pages>
</sb:host>
</sb:reference>
</ce:bib-reference>
</ce:bibliography-sec>
</ce:bibliography>
</chapter>
Reply With Quote
  #4 (permalink)  
Old April 21st, 2009, 11:24 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

So you have 'ce:label' elements and want to insert commas after each such element? I am afraid that is not enough information. Please show the parent element of the 'ce:label' elements as well and if 'ce:label' elements have any sibling elements then we need to see them too.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
  #5 (permalink)  
Old April 21st, 2009, 11:34 AM
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The parent element of <ce:label> element is <ce:bib-reference>.

the commons should be add only the child of <ce:bib-reference>tag is <ce:label>.....
Reply With Quote
  #6 (permalink)  
Old April 21st, 2009, 11:40 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You want an identity template to copy everything unchanged:

Code:
<xsl:template match="*">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>
and then supplement this with a special rule:

Code:
<xsl:template match="ce:label[. = '[1]']">
  <xsl:next-match/>
  <xsl:text>,</xsl:text>
</xsl:template>
The <xsl:next-match> instruction is XSLT 2.0 only.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #7 (permalink)  
Old April 21st, 2009, 11:53 AM
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your immediate reply,

I had some more doubt please recfity this below,

How i am declare the supplement <ce:label> in the xsl template and where i need to give the xslt version 2.0 in xslt and xml files.

<xsl:template match="ce:label[. = '[1]']">
<xsl:next-match/>
<xsl:text>,</xsl:text>
</xsl:template>
Reply With Quote
  #8 (permalink)  
Old April 21st, 2009, 12:14 PM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

You simply use version="2.0" on your xsl:stylesheet element:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0">
  <!-- templates go here -->
</xsl:stylesheet>
But you will need an XSLT 2.0 processor for that, like Saxon 9 from http://saxon.sourceforge.net/ or like AltovaXML tools from http://www.altova.com/
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
  #9 (permalink)  
Old April 21st, 2009, 06:14 PM
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Is there any prospect of .NET adding XSLT 2.0 support anytime soon? I think there's a group building some of that functionality on the side, but it seems like a big loophole in the framework.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
Reply With Quote
  #10 (permalink)  
Old April 22nd, 2009, 04:08 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Is there any prospect of .NET adding XSLT 2.0 support anytime soon?

There has been an XSLT 2.0 processor on .NET (namely Saxon) for some years.

If you mean a processor that comes bundled with the .NET platform, you'll have to ask Microsoft. A couple of years ago they said they were working on one, but there's been little further news.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add an attribute to each element bartnowa XSLT 3 November 8th, 2007 12:12 PM
How to add attribute to unbounded element 2BOrNot2B XML 4 January 16th, 2007 03:42 PM
javascript - add element to existing xml? willgotoo XML 4 October 8th, 2004 09:33 AM
How to Add a new element to Dataset after build Namita Crystal Reports 3 October 4th, 2004 01:13 AM
Add Mask To Input Element ritag HTML Code Clinic 4 July 20th, 2004 03:33 PM



All times are GMT -4. The time now is 11:56 PM.


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