[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Copying Namespace Nodes
At 2011-11-27 22:10 +0100, Heiko Niemann wrote:
I have an element I want to copy and in the source it looks like this: I don't think the template needed is very verbose at all since you are limiting yourself to finding the one prefix that is found in the xsi:type= attribute: T:\ftemp>type heiko.xml <?xml version="1.0" encoding="UTF-8"?> <a:elem xmlns:a="example.com/ns/a" xsi:type="nsc:foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:nsc="example.com/ns/sensitive" xmlns:b="example.com/ns/b" xmlns:c="example.com/ns/c" xmlns:z="example.com/ns/z">info</a:elem> T:\ftemp>xslt2 heiko.xml heiko.xsl <?xml version="1.0" encoding="UTF-8"?><a:elem xmlns:a="example.com/ns/a" xmlns:nsc="example.com/ns/sensitive" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="nsc:foo"/> T:\ftemp>type heiko.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"> <xsl:template match="*"> <xsl:copy copy-namespaces="no"> <xsl:for-each select="@xsi:type"> <xsl:copy-of select="../namespace::*[name(.)=substring-before(current(),':')]"/> <xsl:copy/> </xsl:for-each> </xsl:copy> </xsl:template> </xsl:stylesheet> T:\ftemp> I hope this helps. If there is no xsi:type attribute, then no copy of the namespace node is done. . . . . . . . . Ken Thanks for help, Heiko -- Contact us for world-wide XML consulting and instructor-led training Free 5-hour video lecture: XSLT/XPath 1.0 & 2.0 http://ude.my/t37DVX Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|