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 November 26th, 2008, 05:40 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

If your input XML is like
<result>
    <variable CY="2008"/>
    <a1><MyNode1>MyNode1</MyNode1></a1>
    <a1><a2><MyNode1>MyNode1</MyNode1></a2></a1>
    <a1><a2><MyNode1>MyNode1</MyNode1>
            <a3><MyNode2>MyNode2</MyNode2></a3>
        </a2>
    </a1>
</result>
or like
<result>
    <variable CY="2008"/>
    <a1>
        <MyNode1>
            <test>MyNode1</test>
            <test>MyNode1</test>
        </MyNode1>
    </a1>
    <a1><a2><MyNode1>
            <test>MyNode1</test>
            <test>MyNode1</test>
        </MyNode1></a2>
    </a1>
    <a1>
        <a2><MyNode1>
                <test>MyNode1</test>
                <test>MyNode1</test>
            </MyNode1>
            <a3><MyNode2>
                <test>MyNode2</test>
                <test>MyNode2</test>
            </MyNode2></a3>
        </a2>
    </a1>
</result>
then the template mentioned below will give the required result.
<xsl:template match="/">
        <xsl:apply-templates select="//MyNode1 | //MyNode2 | //MyNodeN"/>
    </xsl:template>

If our understanding is wrong then show the relevant parts of input xml and xsl. This way would help you much.

------
Rummy
 
Old November 26th, 2008, 06:09 AM
Authorized User
 
Join Date: Nov 2008
Posts: 12
Thanks: 2
Thanked 1 Time in 1 Post
Send a message via Yahoo to mail4kaja
Default

Huh... I have pointed out the problem. I'm getting the output, when I remove the schema url from my xml instance. But, I need to have my xml input with all the reference to its schema(s).

Is there anything I have left out in my XSL to inform about the namespaces?

R Kaja Mohideen
http://www.vhost4all.com/
 
Old November 26th, 2008, 06:27 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

What schema reference?

You haven't shown us your input XML or what output you want (vs. what output you are getting).

/- Sam Judson : Wrox Technical Editor -/
 
Old November 26th, 2008, 06:34 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Take a look at the first post in this forum, it has links to matching nodes in namespaces.

--

Joe (Microsoft MVP - XML)
 
Old November 26th, 2008, 06:36 AM
Authorized User
 
Join Date: Nov 2008
Posts: 12
Thanks: 2
Thanked 1 Time in 1 Post
Send a message via Yahoo to mail4kaja
Default

This is how my input xml starts

<?xml version="1.0" encoding="UTF-8"?>
<Configuration xsi:schemaLocation="Configuration A_Config.xsd" xmlns="Configuration" xmlns:dataAttr="dataAttr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
.
.
.
</Configuration>

I get output when I change it to
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
.
.
.
</Configuration>

How to overcome this ?

R Kaja Mohideen
http://www.vhost4all.com/
 
Old November 29th, 2008, 09:30 AM
Authorized User
 
Join Date: Nov 2008
Posts: 12
Thanks: 2
Thanked 1 Time in 1 Post
Send a message via Yahoo to mail4kaja
Default

Anyone out there.... how to resolve this issue?

R Kaja Mohideen
http://www.vhost4all.com/
 
Old November 29th, 2008, 09:41 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

If you use XSLT 1.0 then you need to bind a prefix to the default namespace and use that prefix in XPath expressions and in match patterns to qualify element names e.g.
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0"
  xmlns:df="Configuration">

  <xsl:template match="df:Configuration">
    <xsl:apply-templates select=".//df:Foo | .//df:Bar"/>
  </xsl:template>
If you are using XSLT 2.0 then you can use the xpath-default-namespace attribute e.g.
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0"
  xpath-default-namespace="Configuration">

  <xsl:template match="Configuration">
    <xsl:apply-templates select=".//Foo | .//Bar"/>
  </xsl:template>
--
  Martin Honnen
  Microsoft MVP - XML
 
Old November 29th, 2008, 11:41 AM
Authorized User
 
Join Date: Nov 2008
Posts: 12
Thanks: 2
Thanked 1 Time in 1 Post
Send a message via Yahoo to mail4kaja
Default

Thanks a lot. I got it working. :)

R Kaja Mohideen
http://www.vhost4all.com/
 
Old November 29th, 2008, 12:09 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:Originally posted by mail4kaja
 Anyone out there.... how to resolve this issue?

R Kaja Mohideen
http://www.vhost4all.com/
Yes, dozens. That's why I posted the answer but, apparently, you couldn't be bothered to read it.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Apply-templates combined with with-param ? Smirre XSLT 6 November 11th, 2008 08:25 AM
Difference between call-template ,apply-templates vikkiefd XSLT 4 March 12th, 2008 05:09 AM
apply-templates problem within for-each loop mister_mister XSLT 2 January 22nd, 2007 05:40 PM
Templates Won't Apply neilac333 XSLT 5 October 26th, 2006 01:39 PM
how to exclude elements in the result tree output ntmt XSLT 0 May 25th, 2006 10:33 AM





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