1

I am in the process of transforming an XML file, using a map based on a subtype in the header.

To make this logic happen I've used an xsl:if inside a template that matches on the root node.

<xsl:template match="/">
  <xsl:variable name="var:invoiceSubtype" select="//Header/InvoiceType/text()"></xsl:variable>
  <xsl:if test="$var:invoiceSubtype = 'Invoice'">

Inside the xsl:if I've pasted the XSLT code for the map, without changing the xpath, but some of my elements are not showing any data, like this one:

<BELNR>
   <xsl:value-of select="/Header/InvoiceNumber/text()" />
</BELNR>

The structure of my schema up until the InvoiceType looks like this:

enter image description here

Using the double slash to select the element works, but I'd rather avoid using that, since there might be duplicate named elements.

Is there a way of showing where you currently are in the source schema when selecting nodes? I'm unsure as to what the correct path is.

Leth
  • 1,033
  • 3
  • 15
  • 40

1 Answers1

1

You can just change to the full XPATH starting from the root to avoid using //Header/InvoiceType/text(), use: /CDM_PurchaseInvoice/Header/InvoiceType/text() instead.

Also if you are using namespaces you should take it into account in your xpath or by using the syntax /x:List/x:Fields/x:Fiels or /*[name()='List']/*[name()='Fields']/*[name()='Field'] otherwise you might end up extracting nothing even if the xpath looks correct at first glance.

see: Xml Namespace breaking my xpath!

Allan
  • 12,117
  • 3
  • 27
  • 51