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="http://www.w3.org/2001/XMLSchema-instance">

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="http://www.w3.org/1999/XSL/Transform" version="1.0">

      now becomes:

      <xsl:stylesheet xmlns:t="http://www.mynamespace" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 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:
    xpath-default-namespace="http://www.mynamespace"

sources

Post a Comment

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


Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/remydamo/websites/qc4blog/www/wp-content/plugins/sweetcaptcha-revolutionary-free-captcha-service/library/sweetcaptcha.php on line 81

Warning: fsockopen() [function.fsockopen]: unable to connect to www.sweetcaptcha.com:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /home/remydamo/websites/qc4blog/www/wp-content/plugins/sweetcaptcha-revolutionary-free-captcha-service/library/sweetcaptcha.php on line 81