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
  • 941
  • 3
  • 12
  • 29
  • Advice to newcomers: If an answer solves your problem, please accept it by clicking the large check mark (✓) next to it and optionally also up-vote it (up-voting requires at least 15 reputation points). If you found other answers helpful, please up-vote them. Accepting and up-voting helps future readers. Please see [the relevant help-center article][1] [1]: http://stackoverflow.com/help/someone-answers – Allan Mar 13 '18 at 09:03

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
  • 11,650
  • 3
  • 27
  • 49