XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Ali EbrahimSubject: changing the name of an attribute in a source xml
Author: Ali Ebrahim
Date: 05 Apr 2007 01:20 AM
Ivan,


Would it be possible if you could assist me with sample xsl code that would copy all elements and attributes across to target xml, but while coping if the xsl it comes across an attribute of name = xsi_type it needs to change it to xsi:type in the target xml.

I'll write the above requirement in another fashion:
Sample code to change all occurance of attibutes name "xsi_type" in Source XML to "xsi:type"

You might want to refer to my previous post "Strip Empty Element Trees" for background on our xml structure


Thanx
Ali



Postnext
Nitesh JSubject: changing the name of an attribute in a source xml
Author: Nitesh J
Date: 05 Apr 2007 10:48 PM
Hi,

I am one of Ali's colleagues and I have just "finished" implementing the above requirement. However, there MUST be a more efficient way of implementing this.

All I am trying to do in this XSLT is copy the entire source XML and replace ALL attributes with name xsi_type with xsl:type. Its a shame that I had to implement a for-each loop to ensure that all attributes within an element got copied if a match was found.

Is there any way I can achieve this with just one 'template match' and using the 'translate' function.

Thanks,
Nitesh


DocumentFindAndReplace.xsl

Postnext
Tony LavinioSubject: changing the name of an attribute in a source xml
Author: Tony Lavinio
Date: 06 Apr 2007 12:27 AM
Way more efficient.


Unknownxsi_type.xsl

Postnext
Nitesh JSubject: changing the name of an attribute in a source xml
Author: Nitesh J
Date: 06 Apr 2007 01:24 AM
Nice. And perfect. Thanks.

Postnext
Ali EbrahimSubject: changing the name of an attribute in a source xml
Author: Ali Ebrahim
Date: 10 Apr 2007 07:50 AM
Tony,

Thanx for the sample xsl. When I execute the sample code on the attached Source XML, I have noticed the following in the result attached xml:


1)Reordered SOAP Envelope namespace declaration....I think Siebel Requires this in the order of the Source XML
2)Removed all xmlns="" from child elements....Our service provider requires BLANK"" namespaces declared at each child element of myXML
3)Removed XSI declation from myXML node...This is required...else the xsi:type will be invalid
4)Reordered XMLNS declarion on myXML Node.


Are you able to provide us with guidance on on how to preserve the above?


Thanx, Ali
ORIGIN energy – Australia


UnknownSourceXML.xml


UnknownResultXML.xml

Postnext
Tony LavinioSubject: changing the name of an attribute in a source xml
Author: Tony Lavinio
Date: 10 Apr 2007 09:02 AM
These all appear to be artifacts of the XSLT engine you are using.

Note that XML does NOT guarantee the order of attributes, including
the xmlns namespace declarations. There is nothing you can do about
the ordering within an element's declaration. Nor should you, or
any application, care.

Other than that, it should work if the receiver is XML-namespace
compliant. Namespaces nest, and compliant XSLT processors should
emit namespace declarations automatically where needed.

Have you actually tried the results to see if there is a problem?
Your message seems to indicate that you haven't yet.

Finally, which of the XSLT processors within Stylus Studio are you
using?

Postnext
Ali EbrahimSubject: changing the name of an attribute in a source xml
Author: Ali Ebrahim
Date: 10 Apr 2007 09:23 AM
Tony,

The CRM Product that we using and will execute XSLT is Siebel v7.8. This version of Siebel uses the XalanJ processor.

I have tested the result SOAP message and it not not being accepted by the service provider.

WRT to Point 2, do you have any idea why the BLANK xmlns="" and also the xmlns:xsi declaration removed?

Regards,
Ali

Postnext
Ali EbrahimSubject: changing the name of an attribute in a source xml
Author: Ali Ebrahim
Date: 10 Apr 2007 09:34 AM
Tony,

The CRM Product that we using and will execute XSLT is Siebel v7.8. This version of Siebel uses the XalanJ processor.

I have tested the result SOAP message and it not not being accepted by the service provider.

WRT to Point 2, do you have any idea why the BLANK xmlns="" and also the xmlns:xsi declaration removed?

Regards,
Ali

Postnext
Tony LavinioSubject: changing the name of an attribute in a source xml
Author: Tony Lavinio
Date: 10 Apr 2007 12:11 PM
Typically with XSLT engines, the namespace declaration will be
placed in the outermost element in which it is needed.

Which version of Stylus Studio are you using, so that I know
which version of Xalan-J you are testing with? (I'm assuming
you are a Stylus Studio user, since you are posting on the
Stylus Studio support forum, in which we provide free support
for our users.)

Postnext
Nitesh JSubject: changing the name of an attribute in a source xml
Author: Nitesh J
Date: 10 Apr 2007 06:39 PM
Hi,

We are using Stylus Studio 2007 Enterprise Edition (build 735e).

Postnext
Nitesh JSubject: changing the name of an attribute in a source xml
Author: Nitesh J
Date: 10 Apr 2007 08:10 PM
also, note that this problem only occurs because the attribute's name is "xmlns". If I change one of the attribute's name to "xmlnss", the xslt DOES output the blank attribute.

I believe we need to send it as "xmlns".

Is there anyway we can overcome this issue?

Postnext
Ali EbrahimSubject: changing the name of an attribute in a source xml
Author: Ali Ebrahim
Date: 10 Apr 2007 08:54 PM
Tony,

We create the xsl using stylus studio 2007 enterprise suite. The default processor set in Stylus is XalanJ. Siebel v7.8 executes the xsl and uses Xalan(not sure on version) as the processor and Xerces as XML parser.

Also, please note that the service provider requires the consumer to set a default namespace(xmlns="urn1") on the document element(myXML) and a BLANK default namespace on each child element(xmlns="")....in this way the SOAP Body will be schema valid.

Thanx and I look forward to your response.

Regards,
Ali

Postnext
Ali EbrahimSubject: changing the name of an attribute in a source xml
Author: Ali Ebrahim
Date: 11 Apr 2007 01:39 AM
Tony,

We create the xsl using stylus studio 2007 enterprise suite. The default processor set in Stylus is XalanJ. Siebel v7.8 executes the xsl and uses Xalan(not sure on version) as the processor and Xerces as XML parser.

Also, please note that the service provider requires the consumer to set a default namespace(xmlns="urn1") on the document element(myXML) and a BLANK default namespace on each child element(xmlns="")....in this way the SOAP Body will be schema valid.

Thanx and I look forward to your response.

Regards,
Ali

Posttop
Ivan PedruzziSubject: changing the name of an attribute in a source xml
Author: Ivan Pedruzzi
Date: 11 Apr 2007 01:47 AM

Hi Ali,

what you are seeing is an artifact of the preview window that serializes the output XML incorrectly, however the XSLT proposed is correct.

To see the right result click XSLT -> "Generate Java code" then compile and run, you will see the correct result in the output window.

Thnnk you for reporting the problem the upcoming 2007 release 2 will have it fixed.

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.