XSLT with XML source that has a default namespace set to xmlns -
i have xml document default namespace indicated @ root. this:
<myroot xmlns="http://www.mysite.com"> <mychild1> <mydata>1234</mydata> </mychild1> </myroot>
the xslt parse xml not work expected because of default namespace, i.e. when remove namespace, works expected.
here xslt:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:xs="http://www.w3.org/2001/xmlschema"> <xsl:template match="/" > <soap:envelope xsl:version="1.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:body> <newroot xmlns="http://wherever.com"> <newchild> <childid>abcd</childid> <childdata> <xsl:value-of select="/myroot/mychild1/mydata"/> </childdata> </newchild> </newroot> </soap:body> </soap:envelope> </xsl:template> </xsl:stylesheet>
what needs done xslt document translation works properly? needs done in xslt document?
you need declare namespace in xslt, , use in xpath expressions. e.g.:
<xsl:stylesheet ... xmlns:my="http://www.mysite.com"> <xsl:template match="/my:myroot"> ... </xsl:template> </xsl:stylesheet>
note must provide prefix if want refer elements namespace in xpath. while can xmlns="..."
without prefix, , work literal result elements, won't work xpath - in xpath, unprefixed name considered in namespace blank uri, regardless of xmlns="..."
in scope.
Comments
Post a Comment