how to use xmlns prefix with xsl transformation

XSL transformation was working with an xml file without any explicit xmlns namespace, but failed on file with explicit namespace such as in below code:

<FpML xmlns="http://www.mynamespace" xmlns:xsi="">

Reason is because by default, XSL version 1.0 is considering default namespace to be blank.

As such, in order to match a file with explicit namespace, possibilities are:

  1. remove namespace from input file
  2. change xsl by:
    1. adding a namespace prefix in header that is matching the input namespace
      <xsl:stylesheet xmlns:xsl="" version="1.0">

      now becomes:

      <xsl:stylesheet xmlns:t="http://www.mynamespace" xmlns:xsl="" version="1.0">
    2. prefix all nodes used in xpath requests with previously defined prefix
      <xsl:param name="data" select="/FpML/dealEntry/eventAction" />

      now becomes:

      <xsl:param name="data" select="/t:FpML/t:dealEntry/t:eventAction" />
  3. change xslt version from 1.0 to 2.0 and use parameter:


Post a Comment

Your email is never published nor shared. You're allow to say what you want...