Andrus
Andrus

Reputation: 27899

How to perform xsl transformation if custom namespaces are used

Source xml contains custom namespaces:

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <ns:getBuyInvoiceResponse xmlns:ns="http://iws.itella.ee">
      <ns:return>
        <E_Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...

XSL contaisn also those namespaces:

<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://iws.itella.ee"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"

and they are used in selector

  <xsl:template match="/soapenv:Envelope/soapenv:Body/ns:getBuyInvoiceResponse/E_Invoice/Invoice/InvoiceItem/InvoiceItemGroup/*">

XSLT transformation using http://www.utilities-online.info/xsltransformation creates empty document. How to fix this so that document content is also created?

Upvotes: 0

Views: 45

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 116959

For one thing, E_Invoice is a child of ns:return, not ns:getBuyInvoiceResponse - so your 2nd template matches nothing.

Note also that a match pattern is different from a select expression: you don't need to spell out the full path. This:

<xsl:template match="InvoiceItemGroup/*">

would have worked just as well.

Finally, note that you only need to use xsl:element if the element's name must be calculated. Otherwise it's shorter and better to use literal result elements.

Upvotes: 1

Related Questions