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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + First time to Stylus Studio 20... (3)
-> + xsl:if test statement result t... (4)
-> + XSLT for dynamic target fields (4)
-> + Remove duplicates (2)
-> + XML-XSL grouping issue while d... (2)
-> + Two XML files. Two Tables. One... (3)
-> + Saxon 9.3 with XSLV (2)
-> - How do I remove the text strin... (1)
-> + Xpath of each element (3)
-> + Attributes - required vs optio... (2)
-> + XML schema to XML schema with ... (2)
-> + how to preserve the & in X... (2)
-> + how to use variables within (2)
-> + need help in XSLT programming (3)
-> + XSLT Mapper Option... Where i... (3)
-> - Selecting element based on att... (1)
-> + replace question (2)
-> - select other node based on one... (1)
-> - XSLT question... (1)
-> - Mapper and XSL (1)
-> - Copying XML as is with one cha... (1)
-> - Help with XSLT (1)
-> - XSL repeat the parent node for... (1)
-> - xls to xml (1)
-> - Stylus support non-backreferen... (1)
-> - Assigning records to existing ... (1)
-> + xsl:for-each and key() (2)
-> + tags containing a: (2)
-> - Create a namespace in output f... (1)
-> - XML Converters problem on UNIX (1)
-> - Copy XML Based on IF Condition... (1)
-> - csv counting dependencies (1)
-> + For extension function, could ... (2)
-> - XML XSLT Transformation (1)
-> + Transform XSD to another XSD (3)
-> - New to Stylus (1)
-> + my enterprise install doesn't ... (2)
-> - Replace line in XML (1)
-> - 5010 HIPAA - Example EDI files... (1)
-> - Display table in two columns f... (1)
-> + java.lang.RuntimeException (4)
-> + Select Value-Of Qualified Elem... (2)
-> + Validating different sets of r... (2)
-> + Passing complete source docume... (2)
-> - XSLT to sort XML per schema (1)
-> - XSL to select the group of row... (1)
-> + first ancestor of a type (2)
-> - Column Width Adjustment (1)
-> + XSLT breakpoint being ignored ... (6)
-> - Creating a tab delimited file (1)
-> - Invalid characters in xml (1)
-> + Creating XSLT File Based on XS... (2)
-> - Unable to filter InputStream f... (1)
-> + finding a list of values (7)
-> - TEMP directory question (1)
-> - [HELP] Template and namespace (1)
-> - The prefix "xsl" for element "... (1)
-> - Need help comparing dates in x... (1)
-> - trying to sort a list of artic... (1)
-> + Count unique values using XSLT (3)
-> + Dot "." vs. self::node() (2)
-> + Output from report and XSL do ... (2)
-> + XSL report (2)
-> + cannot see valid values in the... (2)
-> - sum function help (1)
-> + XSLT transformation problem (2)
-> + Flat To nested XML using Keys (3)
-> - XSLT Editor autocomplete funct... (1)
-> - Receiving an argument from a l... (1)
-> + Can't using the Xalan-J in Sty... (2)
-> + Need help testing to see if th... (2)
-> + Any good way to handle repeati... (2)
-> - Renaming child element name wh... (1)
-> + What to do to only how last 4 ... (2)
-> + Help to access an element with... (3)
-> - Multiplication for-each (1)
-> - XSL / X-Path query (1)
-> - Help in creating XSD (1)
-> + JAVASCRIPT Inside XSL (2)
-> + is at possible to create edita... (2)
-> + Grouping on Multiple Field (2)
-> + XSLT 1.0 Grouping Small change... (2)
-> + Revision bar based on the page... (2)
-> + xslt to rtf (2)
-> + XEP/FOP Error (3)
-> + XML to XML Transformation (3)
-> + This XSLT has stumped me.. (2)
-> + converting XML to EACOM format (2)
-> + Stylus with XSLT 1.0 + EXSLT T... (2)
-> + Xslt Mapper (2)
-> - xml to xsl (1)
-> - creating a website (1)
-> - XML to PDF using XML Publisher... (1)
-> - Replace nodes (1)
-> - New to XSLT, need help with a ... (1)
-> - Modify XSLT - Have List of Cha... (1)
-> - Replace nodes in one xml file ... (1)
-> - Alternate Row Colour (1)
-> - convert text to XML and then m... (1)
-> - CDATA to XML - work with trans... (1)
-- Previous [61-80] [81-100] [101-120] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Naveen KSubject: XSLT Problem using Namespace and SchemaLocation
Author: Naveen K
Date: 29 Nov 2005 07:36 PM
Hello Everybody
This is first post...

I am having problems with XML transformation when the XML file has namespace and schemaLocation specified. The transformation just returns an null sets.

Here is the sample code I am using:
XML:
<response-data xmlns="http://w3.org" xmlns:xsi="http://something.com/sample" schemaLocation="http://something.com/sample ex/sample">
<response-data-vals lname="Smith" fname="Allen" dob="19500101"/>
</response-data>

XSL:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:myns="http://something.com/sample ex/sample">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:element name="FirstName">
<xsl:valueof select="myns:response-data/response-data-vals/@fname"/>
</xsl:element>
<xsl:element name="LastName">
<xsl:valueof select="myns:response-data/response-data-vals/@lname"/>
</xsl:element>
<xsl:element name="DOB">
<xsl:valueof select="myns:response-data/response-data-vals/@dob"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

If the Namespace and schemaLocation are not specified in the XML then everything works well.But those values being specified transformation returns null sets.

Any help will be greatly appreciated.

Thanks
Naveen

Postnext
(Deleted User) Subject: XSLT Problem using Namespace and SchemaLocation
Author: (Deleted User)
Date: 29 Nov 2005 10:13 PM
Hi Naveen,
I fixed a couple of problems in your sample.

1) Your input XML file should specify its namespace like this:
<response-data
xmlns="http://something.com/sample ex/sample">
<response-data-vals lname="Smith" fname="Allen" dob="19500101"/>
</response-data>
OR, like this:
<myns:response-data
xmlns:myns="http://something.com/sample ex/sample">
<myns:response-data-vals lname="Smith" fname="Allen" dob="19500101"/>
</myns:response-data>

Both are equivalent.

2) Your .xsl file should be like this:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:myns="http://something.com/sample ex/sample">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:element name="FirstName">
<xsl:value-of select="myns:response-data/myns:response-data-vals/@fname"/>
</xsl:element>
<xsl:element name="LastName">
<xsl:value-of select="myns:response-data/myns:response-data-vals/@lname"/>
</xsl:element>
<xsl:element name="DOB">
<xsl:value-of select="myns:response-data/myns:response-data-vals/@dob"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

Note the changes in the xsl:value-of elements.

The actual value for the namespace "http://something.com/sample ex/sample" doesnt matter, as long as it is identical in both files.

Good luck,
Clyde

Postnext
Naveen KSubject: XSLT Problem using Namespace and SchemaLocation
Author: Naveen K
Date: 29 Nov 2005 10:23 PM
Thanks Clyde
I have no control over the input XML, and I wont be able to change any thing on that.
In the xsl translation I am specifying the xmlns as the schemaLocation from the XML i.e., xmlns:myns="schemaLocation" but thats not working.

What needs to be changed on the XSL?

Thanks

Postnext
Ivan PedruzziSubject: XSLT Problem using Namespace and SchemaLocation
Author: Ivan Pedruzzi
Date: 30 Nov 2005 12:00 AM
Naveen,

In your example the default name-space is http://w3.org also the original style-sheet doesn't generate well-formed XML, see the following example


<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:myns="http://w3.org">
<xsl:output method="xml"/>
<xsl:template match="/">
<root>
<xsl:element name="FirstName">
<xsl:value-of select="myns:response-data/myns:response-data-vals/@fname"/>
</xsl:element>
<xsl:element name="LastName">
<xsl:value-of select="myns:response-data/myns:response-data-vals/@lname"/>
</xsl:element>
<xsl:element name="DOB">
<xsl:value-of select="myns:response-data/myns:response-data-vals/@dob"/>
</xsl:element>
</root>
</xsl:template>
</xsl:stylesheet>


Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
Naveen KSubject: XSLT Problem using Namespace and SchemaLocation
Author: Naveen K
Date: 30 Nov 2005 08:49 AM
Thanks Ivan

I had this reformatted to reflect your suggestions and it still doesn't works. Please check this XML and XSL and suggest me if there is something wrong in the XSL.

XML:
<?xml version="1.0" encoding="UTF-8"?>
<response-data xsi:schemaLocation="http://xml-schemas.something.com/sample sample/sampleTest.xsd"
xmlns="http://xml-schemas.something.com/sample"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<response-data-vals lname="Smith" fname="Allen" dob="19500101"/>
</response-data-vals>
</response-data>


XSL:
<?xml version='1.0' encoding='UTF-8' ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:java="http://xml.apache.org/xslt/java"
exclude-result-prefixes="java" extension-element-prefixes="java"
xmlns:myns="http://xml-schemas.something.com/sample sample/sampleTest.xsd">

<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<Division>
<PersonalData>
<FirstName>
<xsl:value-of select="myns:response-data/myns:response-data-vals/@fname"/>
</FirstName>
<LastName>
<xsl:value-of select="myns:response-data/myns:response-data-vals/@lname"/>
</LastName>
<DOB>
<xsl:value-of select="myns:response-data/myns:response-data-vals/@dob"/>
</DOB>
</PersonalData>
</Division>
</xsl:template>
</xsl:stylesheet>

Thanks again and I appreciate your response.

Naveen

Postnext
(Deleted User) Subject: XSLT Problem using Namespace and SchemaLocation
Author: (Deleted User)
Date: 30 Nov 2005 09:52 AM
Naveen,

First, your sample input .xml is not well-formed. You are terminating the response-data-vals element 2 times. The xml should be like this:

<?xml version="1.0" encoding="UTF-8"?>
<response-data xsi:schemaLocation="http://xml-schemas.something.com/sample sample/sampleTest.xsd"
xmlns="http://xml-schemas.something.com/sample"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<response-data-vals lname="Smith" fname="Allen" dob="19500101"/>
</response-data>

Second, we need to get the namespaces to match between the two documents.
In the .xml file, you are specifying the namespace with this attribute:
xmlns="http://xml-schemas.something.com/sample"
The other attributes (xsi:schemaLocation and xmlns:xsi) have nothing to do with this problem. You can delete them or leave them it makes no difference.
In the .xsl file, you are specifying the namespace with this attribute:
xmlns:myns="http://xml-schemas.something.com/sample sample/sampleTest.xsd"
The value is not the same, as in the .xml file. Change it to be this:
xmlns:myns="http://xml-schemas.something.com/sample"
and everything will work.

The important thing is that the value of the xmlns= in the .xml file must match the value of the xmlns:myns= in the .xsl file. You can use any string you want, "http://xml-schemas.something.com/sample" is OK. "blah" is also OK, as long as is is the same in both files.

You seem to be trying to use the name of a schema file as the namespace name. That is also OK, but the fact that it is a schema file is not important. You don't specify a schema using the namespace mechanism.

Hope this helps,
Clyde

Postnext
Naveen KSubject: XSLT Problem using Namespace and SchemaLocation
Author: Naveen K
Date: 01 Dec 2005 10:24 AM
Originally Posted: 01 Dec 2005 10:25 AM
Thanks Clyde
That did worked. The termination of the response-data-vals element 2 times was a typo.

Here is another problem, the input XML is inconsistent. Sometimes I recieve xsi:schemaLocation,xmlns and xmlns:xsi and sometimes I just recieve the xsi:schemaLocation.
When I just recieve the xsi:schemaLocation the translation fails. Any idea what needs to be changed in the xsl to handle this problem?

<?xml version="1.0" encoding="UTF-8"?>
<response-data xsi:schemaLocation="http://xml-schemas.something.com/sample sample/sampleTest.xsd">
<response-data-vals lname="Smith" fname="Allen" dob="19500101"/>
</response-data>

Any help will be great.
Thanks
Naveen

Postnext
(Deleted User) Subject: XSLT Problem using Namespace and SchemaLocation
Author: (Deleted User)
Date: 01 Dec 2005 01:17 PM
Naveen,
If there is too much variation in the incoming data, then you are going to run into trouble. If the only variation is that sometimes the data has no namespace, and sometimes it has the namespace "http://xml-schemas.something.com/sample"
then the attached program works. It first tries to find elements in the namespace, then it tries to find elements without a namespace.
There are many other ways to do the same thing, with <xsl:if> or <xsl:choose>

Clyde


Documenttest2.xsl

Postnext
(Deleted User) Subject: XSLT Problem using Namespace and SchemaLocation
Author: (Deleted User)
Date: 01 Dec 2005 01:37 PM
Naveen,
The last sample of input XML which you supplied was also not valid XML.
You won't succeed at getting XSLT to work if your input XML is not valid.

You need to solve that problem first, then work on getting the XSLT to work.

Clyde

Postnext
Naveen KSubject: XSLT Problem using Namespace and SchemaLocation
Author: Naveen K
Date: 01 Dec 2005 01:41 PM
Thanks Clyde
That can be done as a work around.

But is it valid to specify xsi:schemaLocation without having a xmlns or/and xmlns:xsi. My question of whether it is valid arises because I cannot open this file in Internet Explorer and it gives me an error as
"Reference to undeclared namespace prefix: 'xsi'. Error processing resource 'file:///C:/output.xml'. Line 1, Position 148".

<?xml version="1.0" encoding="UTF-8"?>
<response xsi:schemaLocation="http://xml-schemas.something.com/test/samples test/samples">
<response-header status="OK"/>
<response-record CODE="500" NUM="999999" DATE="2005-11-29"> </response-record>
</response>

I appreciate your response and time.

Thanks
Naveen

Postnext
(Deleted User) Subject: XSLT Problem using Namespace and SchemaLocation
Author: (Deleted User)
Date: 01 Dec 2005 02:57 PM
Naveen,

It is not valid to have xsi:.... without xmlns:xsi=....

The sample of XML you sent won't work with IE, Stylus Studio or any other XML processor.

So if you have xsi:schemaLocation= then you must also have xmlns:xsi=

But, the xmlns="...." is totally separate. It has no connection with the other 2. It doesn't care if the other 2 exist and ignores whatever values they may or may not have.

Clyde

Posttop
Naveen KSubject: XSLT Problem using Namespace and SchemaLocation
Author: Naveen K
Date: 01 Dec 2005 03:25 PM
Thanks Clyde
Now it definitely makes some sense for me as why my translation is failing.

Thanks again for all the help.

Naveen

   
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.