 |
| 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
|
|
|
|

April 4th, 2007, 08:55 AM
|
|
Authorized User
|
|
Join Date: Apr 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
xsl by default taking local-name()
Hi All,
i need a small help .
i have a xml which will come with different namespace prefixes.
i need to generate a xsl which will just take the local-name() for all the elements in the xml .
i know i can do it by putting it for all the xsl:value-of select=""
but i want another way where in i can just specify at one place in the entire xsl so that it will always take the local-name() only .
is this possible . If so please send me the reply . i am waiting for your valuable replies.
Thanks In Advance,
Sasi.
A. Sasi
__________________
A. Sasi
|
|

April 4th, 2007, 09:27 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
It's not a problem if different documents use different namespace prefixes, XSLT takes care of that. It's only a problem if they use different namespace URIs. When that happens, my preferred strategy is to first convert the incoming documents to a common namespace before doing the transformation proper. You can do the namespace change with a modified version of the identity transform something like:
<xsl:template match="*">
<xsl:element name="{local-name()}" namespace="preferred-uri">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

April 4th, 2007, 11:03 AM
|
|
Authorized User
|
|
Join Date: Apr 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Michael,
Can you please tell me with a baisc example.
i have a xml like this .
<Purchase Order>
<Orders xmlns="http://Orders.com">
<OrderId>100</OrderId>
</Orders>
<Address xmlns="http://Address.com">
<Name>Sasi</Name>
<City/>
</Address>
</PurchaseOrder>
Now in my xsl i need find values in OrderId tag and Name Tag . but i dont want to use local-name in select attribute . i want to consider only the localnames for the entire xsl document .Isit Possible .If so can you please give me back the xsl .Its needed for my application.
Once again thanks for your immediate response.
Thanks & Regards,
Sasi.A
A. Sasi
|
|

April 4th, 2007, 11:17 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
What part of my response didn't you understand?
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

April 4th, 2007, 11:35 AM
|
|
Authorized User
|
|
Join Date: Apr 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi ,
First i will clearly tell my problem . Then tell me weather the solution proposed by you will rectify my problemor not .
i have a source xml without any namespaces and prefix and i have a xsl generated on top of that source xml which will convert the source xml to target xml structure .
Now we are moving to the ws-i Basic profile compliance . So now i am getting the source xml with namespace prefixes .
And my old xsl doesnt contain any prefixes . So it will not work for the new xml coming with namespace binding .
Now i need to modify the xsl generated
i have the following option
put local-name()="elementname" for all the select attributes .
for this i need to go through the big xsl file and at run time i need to append the local-name() stuff for all the xpaths.
i dont want to do it as there is a problem of doing some thing wrong for the users xsl .
so i need some way where in i can use only the localnames to the entire xsl instead of specifically telling for all the select attributes.
i think i am clear .
Is the solution provided by you earlier will solve my case .
Thanks
Sasi.A
A. Sasi
|
|

April 4th, 2007, 11:41 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
As I said in my earlier response, my preferred approach to this problem is NOT to change the stylesheet so that it ignores namespaces, but rather (using a second stylesheet) to convert one of the varieties of XML document into the other variety before you apply the real transformation.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

April 4th, 2007, 11:53 AM
|
|
Authorized User
|
|
Join Date: Apr 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi ,
So that u mean first copy the source xml into another xml which will not contain any namespaces . and then apply the original style sheet to transform the converted xml .
I think by this performance can decrease because we are doing double transformation here . As my source xml contains real banking xmls this is something like 10000 elements in the entire document .
There is no otherway to do the transformation in a single shot by only considering local-names() in the xml .
Thanks
A. Sasi
|
|

April 4th, 2007, 12:09 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
In general a pipeline architecture using multiple small transformation steps often performs better than a single more complex transformation. There are a number of reasons for this, for example XSLT processors are likely to handle template rules of the form match="x" much more efficiently than match="*[local-name()='x']" - though of course that depends on the processor.
Another reason is that if 70% of your source documents use one format and 30% another, then 70% of transformations will perform better (because they only need one stylesheet and it is simpler because it only handles the one case) while only 30% will perform worse.
You can arrange your pipeline using SAX events to feed the XML from the first stylesheet to the second, which saves the cost of serializing and parsing; or you can even do both stages in a single stylesheet, using an xsl:variable to hold the intermediate result.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

April 4th, 2007, 12:19 PM
|
|
Authorized User
|
|
Join Date: Apr 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i am using a xalan engine to transform the xml's .I think xalan template creation with the style sheet is a heavy operation . so we need to create two xalan template objects one for one xsl and the other for original xsl .
is that is not a performance decrease ?
Any way its really very good to have this knowledge with you .
Thanks for your postings.
A. Sasi
|
|

April 4th, 2007, 01:02 PM
|
|
Authorized User
|
|
Join Date: Apr 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
No Reply?
A. Sasi
|
|
 |