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

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

October 22nd, 2007, 05:29 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|

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

October 22nd, 2007, 05:56 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|

October 22nd, 2007, 06:20 AM
|
|
Authorized User
|
|
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Perfect!! That's the correct syntax I was looking for.
Thanks Sam for help.
Pankaj
|
|

October 22nd, 2007, 09:51 AM
|
|
Authorized User
|
|
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

October 22nd, 2007, 10:17 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
That depends a lot on what the error is?
/- Sam Judson : Wrox Technical Editor -/
|
|

October 22nd, 2007, 10:31 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

October 22nd, 2007, 11:53 PM
|
|
Authorized User
|
|
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

October 23rd, 2007, 02:44 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|
 |