Hi Guys,

How can I convert XPath without namespace and prefix to the XPath with namespace and prefix.

For Eg:

I have a XML file like this

<?xml version="1.0" encoding="UTF-8"?>
<ns0:mt_test xmlns:ns0="http://hvpar">
<RECORD1>
<FIELD1>1</FIELD1>
<FIELD2>2</FIELD2>
</RECORD1>
</ns0:mt_test>

and I need to write XPath Expression to check whether FIELD1 contains value 1 or not

xpath="/ns0:mt_test/RECORD1/FIELD1" expect = "1"

But the above statement fails in executing the XPath expression.

Please guide how to handle namespace and prefix in above situation.

Thanks,
Raju.

You need to add the ns0 namspace to your stylesheet

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0" xmlns:ns0="http://hvpar" >

   <xsl:variable name="checkfield1">
      <xsl:choose>
         <xsl:when test="/ns0:mt_test/RECORD1/FIELD1 != 1">false</xsl:when>
         <xsl:otherwise>true</xsl:otherwise>
      </xsl:choose>
   </xsl:variable>

   <xsl:template match="/">
      <xsl:message><xsl:value-of select="$checkfield1"/></xsl:message>
   </xsl:template>

</xsl:stylesheet>