0

If I have this xml:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope>
<m:RgWsPublicFirmActRtUser>
      <m:firmActDescr>ΑΛΛΟ ΛΙΑΝΙΚΟ ΕΜΠΟΡΙΟ ΣΕ ΜΗ ΕΞΕΙΔΙΚΕΥΜΕΝΑ ΚΑΤΑΣΤΗΜΑΤΑ</m:firmActDescr>
      <m:firmActKind>2</m:firmActKind>
      <m:firmActKindDescr>ΔΕΥΤΕΡΕΥΟΥΣΑ</m:firmActKindDescr>
      <m:firmActCode>47191000</m:firmActCode>
   </m:RgWsPublicFirmActRtUser>

   <m:RgWsPublicFirmActRtUser>
      <m:firmActDescr>ΛΙΑΝΙΚΟ ΕΜΠΟΡΙΟ ΕΙΔΩΝ ΔΩΡΩΝ ΓΕΝΙΚΑ</m:firmActDescr>
      <m:firmActKind>2</m:firmActKind>
      <m:firmActKindDescr>ΔΕΥΤΕΡΕΥΟΥΣΑ</m:firmActKindDescr>
      <m:firmActCode>47191008</m:firmActCode>
   </m:RgWsPublicFirmActRtUser>
</env:Envelope>

And I use this XSLT:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h3>Δραστηριότητες</h3>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th style="text-align:left">Δραστηριότητα</th>
        <th style="text-align:left">Αριθμός δραστηριότητας</th>
        <th style="text-align:left">Περιγραφή δραστηριότητας</th>
        <th style="text-align:left">Κωδικός δραστηριότητας</th>
      </tr>
      <xsl:for-each select="Envelope/RgWsPublicFirmActRtUser">
      <tr>
        <td><xsl:value-of select="firmActDescr"/></td>
        <td><xsl:value-of select="firmActKind"/></td>
        <td><xsl:value-of select="firmActKindDescr"/></td>
        <td><xsl:value-of select="firmActCode"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

All works fine, but when I have a namespace in the input XML:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m="http://gr/gsis/rgwspublic/RgWsPublic.wsdl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Instead of no namespaces:

<env:Envelope> 

The XSLT won't work

My problem is that the XML is received from a 3rd party and I can't control the content. I need to process it as it is. Maybe I can replace the big env:Envelope and the small env:Envelope within an inside server process, but is there anyway I can make the XSLT work without changing the XML?

1 Answer 1

1

To match namespaced elements in XSLT you have to declare a namespace prefix in the stylesheet for the same namespace URI, and use that prefix in your XPath expressions:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:m="http://gr/gsis/rgwspublic/RgWsPublic.wsdl">

  <xsl:template match="/">
    <!-- ... -->
    <xsl:for-each select="env:Envelope/m:RgWsPublicFirmActRtUser">

(m: namespace URI taken from your comment). Namespace URIs do not have to be real URLs that a browser can fetch, they are simply treated as unique identifiers for the namespace. Some XML technologies use "URN" identifiers for their namespaces (like urn:example:namespace) instead of http URLs.

Sign up to request clarification or add additional context in comments.

1 Comment

the m url is <m:rgWsPublicAfmMethodResponse xmlns:m="gr/gsis/rgwspublic/RgWsPublic.wsdl"> but its strange i cant find that url type of url

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.