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 August 16th, 2012, 08:07 AM
sat sat is offline
Registered User
 
Join Date: Aug 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Exclude xlmns attribute

Hello,

I have the following xsl and xml part and the output...

My issue is that I want to exclude only the xmlns attribute from the output.

Any advices???

XSL

At the beggining
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">


<xsl:choose>
<xsl:when test="./str[@id='aaa'] !=''">
<xsl:element name="First">
<xsl:value-of select="./str[@id='aaa']"/>
</xsl:element>
</xsl:when>
<xsltherwise>
<xsl:element name="aaa">
<xsl:attribute name="xsi:nil">true</xsl:attribute>
</xsl:element>
</xsltherwise>
</xsl:choose>


XML
And a very simple xml file which is like this:

<str id="aaabb"></str>


Result
<First xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />

Expected Result
<First xsi:nil="true"/>


Thank you in advance
 
Old August 16th, 2012, 08:23 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

In your expected result you have:
Code:
<First xsi:nil="true"/>
which uses the nil attribute within the namespace referred to by the xsi prefix (http://www.w3.org/2001/XMLSchema-instance).
So you can't remove the declaration of this namespace mapping from the results.
__________________
Joe
http://joe.fawcett.name/

Last edited by joefawcett; August 16th, 2012 at 08:24 AM.. Reason: Tidy up
 
Old August 16th, 2012, 09:02 AM
sat sat is offline
Registered User
 
Join Date: Aug 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So the result will be as it is and I can change it as expected?

And everytime that you want to extract the xsi:nil="true" you will have also the xmlns:xsl.......???

<First xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</First>

At least do you if there is a solution to have the following:

<First xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>

Thanks
 
Old August 16th, 2012, 09:35 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sorry, I thought I explained how if you want to use xsi:nil you need to declare the prefix to namespace mapping. I don't really understand what your second post is asking.
__________________
Joe
http://joe.fawcett.name/
 
Old August 16th, 2012, 09:49 AM
sat sat is offline
Registered User
 
Join Date: Aug 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My problem is that the result is :

<First xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</First>

And I want this:

<First xsi:nil="true" />

Without the 2nd attribute and to close the element in the same tag

I tried Also to do the following in the xsl:

<First xsi:nil="true" />

instead of this:

<xsl:element name="First">
<xsl:attribute name="xsi:nil">true</xsl:attribute>
</xsl:element>

And the result is:

<First xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />

So now I want only to remove the 2nd attribute...

Thanks
 
Old August 16th, 2012, 09:56 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sorry, that can't be done using XSLT because your required result is not well-formed XML. You can get the self-closed element by doing this:
Code:
<xsl:choose>
<xsl:when test="./str[@id='aaa'] !=''">
<xsl:element name="First">
<xsl:value-of select="./str[@id='aaa']"/>
</xsl:element>
</xsl:when>
<xsltherwise>
<First xsl:nil="true" />
</xsl:otherwise>
</xsl:choose>
but you can't use xsl:nil attribute without having the
Code:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
declaration present at least once in the stylesheet.
__________________
Joe
http://joe.fawcett.name/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Select nodes whose attribute matches another node's attribute? nikolai XSLT 5 April 18th, 2018 11:30 AM
Exclude Namespace Atribute bonekrusher XSLT 3 May 4th, 2007 08:18 AM
Using a linkdoc to exclude rows geordaa XSLT 1 August 24th, 2006 11:19 AM
Exclude Nodes seanhaggerty XSLT 1 February 3rd, 2005 06:00 AM
Exclude Certain Forms Ben Horne Access VBA 11 March 16th, 2004 03:06 PM





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