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 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
 
Old April 21st, 2009, 11:00 AM
Friend of Wrox
 
Join Date: Nov 2007
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
 
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>
 
Old April 21st, 2009, 11:24 AM
Friend of Wrox
 
Join Date: Nov 2007
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
 
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>.....
 
Old April 21st, 2009, 11:40 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
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>
 
Old April 21st, 2009, 12:14 PM
Friend of Wrox
 
Join Date: Nov 2007
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
 
Old April 21st, 2009, 06:14 PM
Friend of Wrox
 
Join Date: Jun 2007
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.
 
Old April 22nd, 2009, 04:08 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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





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





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