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 November 24th, 2009, 11:17 AM
Authorized User
 
Join Date: Nov 2009
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
Unhappy applying an attribute to children value while copying

Hi,

Suppose we were having:

<group shared="true">
<element name="a" type="xsd:string" shared="false"/>
<element name="b" type="xsd:string" shared="false"/>
</group>
<element name="c" type="xsd:string" shared="false"/>

which should be come:

<element name="a" type="xsd:string" shared="true"/>
<element name="b" type="xsd:string" shared="true"/>
<element name="c" type="xsd:string" shared="false"/>

In other words, the group/@shared takes precedence over the same child attribute and is removed from the output. How to go about this in XSLT 1.1?
Hope I am not being too ignorant here, feels like a really easy problem...
 
Old November 24th, 2009, 11:32 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Firstly, XSLT 1.1 doesn't exist. It was withdrawn quite a while ago. (Yes, there's boilerplate text on this forum that refers to it! It's obsolete too...)

This one's quite easy (in XSLT 1.0)

Code:
<xsl:template match="group/element">
  <xsl:copy>
     <xsl:copy-of select="@type|@name|../@shared"/>
  </xsl:copy>
</xsl:template>
<xsl:template match="element">
  <xsl:copy-of select="."/>
</xsl:template>
__________________
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
searching children of ancestors mphare XSLT 2 October 8th, 2008 01:09 PM
help with nodes/children bmmayer XML 0 July 13th, 2007 05:04 PM
MDI Children angelboy C# 2005 5 June 28th, 2007 06:08 AM
Access to attribute values from class of attribute jacob C# 1 October 28th, 2005 01:11 PM
get all children nodes maratg XSLT 4 November 7th, 2003 02:07 PM





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