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 28th, 2009, 03:41 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up Copying without attributes with default values in dtd

1. I have an issue where my below code copies the attributes with default values from the dtd. These attributes are not actually present in the xml file. Is there any way to overcome this? See the element book in my sample xml
2. Also, the entities are transformed as original characters. I need the entities to be copied as such. Is there any way to do this?

<xsl:variable name="article" select="document('file:///E:/Ramesh/2_My_Workouts/XSL/ELS-MRW_Pages/1.xml')"/>

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="ce:include-item">
<xsl:for-each select=".">
<xsl:variable name="item" select="."/>
<xsl:variable name="pii" select="ce:pii"/>
<xsl:copy>
<xsl:copy-of select="*"/>
<xsl:if test="$article//ce:pii[. = $pii]">
<xsl:copy-of select="$article//ce:pii[. = $pii]/following-sibling::ce:pages[1]"/>
</xsl:if>
</xsl:copy>
</xsl:for-each>
</xsl:template>

Sample input XML:
<book version="5.3" docsubtype="enc" xml:lang="en">
<ce:copyright-line>&copy; 2006 Elsevier Ltd. All rights reserved.</ce:copyright-line>

Sample Output XML:
<book xmlns="http://www.elsevier.com/xml/bk/dtd" xmlns:ce="http://www.elsevier.com/xml/common/dtd" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.3" docsubtype="enc" xml:lang="en">
<ce:copyright-line>© 2006 Elsevier Ltd. All rights reserved.</ce:copyright-line>

Any help is appreciated.
__________________
Rummy
 
Old October 28th, 2009, 05:26 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

1. I have an issue where my below code copies the attributes with default values from the dtd.

That's the way the language is defined. However, there's an option in Saxon to suppress this, provided you parse the document using a parser that allows Saxon to determine which attributes were in the original source and which were expanded from the DTD.

2. Also, the entities are transformed as original characters. I need the entities to be copied as such. Is there any way to do this?

No: the XSLT processor only sees the result of XML parsing, which contains the expanded entity references. The usual workaround is to use a non-XML-aware preprocess (e.g. sed/awk) to convert the entity references into normal text, e.g. &copy; to %%copy; and then reverse the process on the final output.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old October 28th, 2009, 08:10 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Many thanks for your valuable ideas mhkay.
__________________
Rummy





Similar Threads
Thread Thread Starter Forum Replies Last Post
Default Rows Based Upon Number of XML Attributes. Mr.T Infopath 0 November 5th, 2007 07:29 PM
copying xml attributes golddog XSLT 1 September 12th, 2007 01:05 PM
Default attributes from DTD while transformation nmahesh567 XSLT 5 March 28th, 2007 03:31 AM
copying values into a column from another table madrob3975 SQL Server 2000 1 December 8th, 2006 03:31 AM
Copying Source Node attributes to output node pvsat XSLT 2 November 3rd, 2005 09:46 AM





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