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 October 22nd, 2007, 05:19 AM
Authorized User
 
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default Suppressing Data

Hi,

I've an xml where I need to suppress few text within few elements. This is basically for print purpose wherein this text info are not required to be printed.

<publisherName>Divine Press</publisherName>
<publisherLoc>XXX</publisherLoc>

The first thing, which is strikes in my mind is to convert these text/data into self defined attribute value, so that they do not appear on page (would prefer @supp-info for all cases).
Like:
<publisherName supp-info="Divine Press"></publisherName>
<publisherLoc supp-info="XXX"></publisherLoc>

The reason I want to retain the data into attribute is because I need get these values back to their original places as they were in XML tree before importing the transformed XML.

Can anyone suggest/guide me whether its good way doing or there is any other better way of acheiving the same.

Any comments i this regard will be immense help.

Pankaj



Pankaj
__________________
Pankaj
 
Old October 22nd, 2007, 05:29 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Simply create a template to match the elements you want to and then store the value in an attribute.

e.g.

<xsl:template match="publisherLoc">
  <publisherLoc>
    <xsl:attribute name="supp-loc" select="string(.)"/>
  </publisherLoc>
</xsl:template>

/- Sam Judson : Wrox Technical Editor -/
 
Old October 22nd, 2007, 05:43 AM
Authorized User
 
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well converting string to attributes values was not my concern here like you suggested and know how to do that. I was looking for the suggestions to do it another better way doing that.

Simply I am trying to avoid making huge list of elements, where I am going to use supp-info. This is for when I will be transforming xml back to its original form.

Thanks

Pankaj
 
Old October 22nd, 2007, 05:56 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well then just replace the specific element with an <xsl:element> tag.

<xsl:template match="publisherLoc | publisherName | etc...">
  <xsl:element name="{local-name()}">
    <xsl:attribute name="supp-info" select="string(.)"/>
  </xsl:elememt>
</xsl:template>

And to convert back

<xsl:template match="*[@supp-info]">
  <xsl:element name="{local-name()}">
    <xsl:value-of select="@supp-info"/>
  </xsl:element>
</xsl:template>

/- Sam Judson : Wrox Technical Editor -/
 
Old October 22nd, 2007, 06:20 AM
Authorized User
 
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Perfect!! That's the correct syntax I was looking for.

Thanks Sam for help.

Pankaj
 
Old October 22nd, 2007, 09:51 AM
Authorized User
 
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This one is done using

<xsl:template match="publisherName | publisherLoc">
    <xsl:element name="{local-name()}">
        <xsl:attribute name="supp-info">
        <xsl:value-of select="string(.)"/>
        </xsl:attribute>
    <xsl:copy-of select="@*"/>
    </xsl:element>
</xsl:template>

Cannot understand why
<xsl:attribute name="supp-info" select="string(.)"/>
is giving error.

Any Ideas!!!


Pankaj

Pankaj
 
Old October 22nd, 2007, 10:17 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

That depends a lot on what the error is?

/- Sam Judson : Wrox Technical Editor -/
 
Old October 22nd, 2007, 10:31 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The select attribute on xsl:attribute is a new feature introduced in XSLT 2.0. Chances are you're using a 1.0 processor.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 22nd, 2007, 11:53 PM
Authorized User
 
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Exactly!!! I am working on 1.0. By the way can you suggest me the best processor (which includes all new functionalities) for XSLT 2.0.
I can see that lots of new good features has been added to 2.0, which are very useful. Are there any other requirements I need to fulfill before going ahead with 2.0.

Thanks for suggestions in advance.

Pankaj

Pankaj
 
Old October 23rd, 2007, 02:44 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

To the best of my knowledge there are only 3 XSLT 2.0 processors.

Gestalt is written in Eiffel and is available here: http://sourceforge.net/projects/gestalt

Saxon is available in Java or .Net flavours: http://www.sf.net/saxon

AltovaXml is also available in Java or COM/.Net flavours: http://www.altova.com/altovaxml

Michael is terribly biased, as he wrote Saxon, but I'd have to say its my personal favourite too.

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
suppressing system message??? aspuser27 Excel VBA 2 June 5th, 2007 01:49 PM
Suppressing content fatex9994 Crystal Reports 0 November 20th, 2006 01:30 PM
Suppressing login KiwiMark .NET Framework 2.0 0 June 13th, 2006 10:58 PM
Suppressing Blank Lines? boomboom BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 April 19th, 2005 08:20 PM
Suppressing/cleaning previous entries gurevle HTML Code Clinic 1 June 24th, 2003 12:08 PM





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