Subject: RE: [xsl] element with namespace From: "Venkateshwar Bommineni" <vbommineni@xxxxxxxxxx> Date: Mon, 30 Sep 2002 16:08:01 -0400 |
thanks that worked. So if i want to inherit that namespace for output elements, Members/Member Can i do in my XSL as, <Members xmlns="http://www.foo.com/namespace/v1"> <xsl:apply-templates select="v1:Test/v1:People"/> </Members> this producing expected result. Or is that a bad practice. thanks Venkat -----Original Message----- From: Wes Kubo [mailto:wkubo@xxxxxxxxxxxxx] Sent: Monday, September 30, 2002 3:19 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] element with namespace This is a simple problem. All the elements in your input XML are in the default namespace http://www.foo.com/namespace/v1, which is declared by the statement xmlns="http://www.foo.com/namespace/v1". In your stylesheet, you are trying to match elements that are NOT in any namespace, therefore you are not getting the output you expect. You need to declare the namespace in your stylesheet and use it as such: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:v1="http://www.foo.com/namespace/v1" exclude-result-prefixes="v1"> <xsl:template match="/"> <Members> <xsl:apply-templates select="v1:Test/v1:People"/> </Members> </xsl:template> <xsl:template match="v1:People"> <xsl:for-each select="v1:Person"> <Member><xsl:value-of select="concat(substring(v1:LName,1,1),'.',v1:FName)"/></Member> </xsl:for-each> </xsl:template> </xsl:stylesheet> Here I'm assuming that there is no namespace for your Members or Member elements. FYI, the exclude-result-prefixes="v1" attribute ensures that the http://www.foo.com/namespace/v1 namespace doesn't show up in your output. Hth. Wes -----Original Message----- From: Venkateshwar Bommineni [mailto:vbommineni@xxxxxxxxxx] Sent: Monday, September 30, 2002 11:38 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] element with namespace Hi all, I am having a problem while trying to match root element which has namespace declaration. here is the test snippet i am trying .. Input XML is: ------------------------------------------------------- <?xml version="1.0"?> <Test xmlns="http://www.foo.com/namespace/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.foo.com/namespace/v1 C:\schema\definition.xsd"> <People> <Person> <FName>fname1</FName> <LName>lname1</LName> </Person> <Person> <FName>fname3</FName> <LName>lname3</LName> </Person> </People> </Test> Input XSL is: --------------------------------------------------------------- <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <Members> <xsl:apply-templates select="Test/People"/> </Members> </xsl:template> <xsl:template match="People"> <xsl:for-each select="Person"> <Member><xsl:value-of select="concat(substring(LName,1,1),'.',FName)"/></Member> </xsl:for-each> </xsl:template> </xsl:stylesheet> Output of above transformation results: --------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <Members/> And if remove the namespace declaration from my input xml it works fine. So is that namespace declaration not allowed or is there any magic property i need to set in XSL to ignore namespace declarations? thanks in advance Venkat XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] element with namespace, Wes Kubo | Thread | [xsl] XSLT transform XSL-FO to CSS, gary cor |
RE: [xsl] replace function, Michael Kay | Date | Re: [xsl] XSLT template from XSLT +, Jeni Tennison |
Month |