Question

I have an XML file that begins like this:

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<MensajeFacturacion xmlns="http://localhost/elegibilidad" AgenteSolicitante="0021">
<Cabecera>
...

I'm trying to import information of this file into Filemaker, but it's impossible because in the node MensajeFacturacion I have xmlns="http://localhost/elegibilidad". If I erase the namespace, the file is imported just fine.

This is what the XSL looks like:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fmp="http://www.filemaker.com/fmpxmlresult" 
                exclude-result-prefixes="fmp">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>

  <xsl:template match="/">
    <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
      <ERRORCODE>0</ERRORCODE>
      <PRODUCT BUILD="03-15-2012" NAME="FileMaker" VERSION="ProAdvanced 12.0v1"/>
      <DATABASE DATEFORMAT="D/m/yyyy" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT="k:mm:ss "/>

      <METADATA>
        <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Codigo_empresa_emisora" TYPE="TEXT"/>
        <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="CUPS" TYPE="TEXT"/>   
      </METADATA>

      <RESULTSET FOUND="">
        <ROW RECORDID="" MODID="" >
          <COL><DATA><xsl:value-of select="//Cabecera/CodigoREEEmpresaEmisora"/></DATA></COL>
          <COL><DATA><xsl:value-of select="//Medidas/CodUnificadoPuntoSuministro"/></DATA></COL>
        </ROW>
      </RESULTSET>
    </FMPXMLRESULT>
  </xsl:template>
</xsl:stylesheet>

How do get the import to work with the namespace?

Was it helpful?

Solution

You need to declare the source document's namespace in the <stylesheet> element, assign it a prefix and use that prefix when addressing the source document's elements. So your stylesheet's root element would look like this:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://localhost/elegibilidad">

(note that it's not necessary to declare the Filemaker namespace here), and your calls to get the data need to be changed to:

<COL><DATA><xsl:value-of select="//ns:Cabecera/ns:CodigoREEEmpresaEmisora"/></DATA></COL>
<COL><DATA><xsl:value-of select="//ns:Medidas/ns:CodUnificadoPuntoSuministro"/></DATA></COL>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top