Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
No doubt a quick one for you experts, but for me it has been a fruitless afternoon.
I have XML that I have been asked to interrogate a bit further (cut down version below...)
What I want to do is output the various parts and represent in html. All I need to add is the env:destination/@branch.

But I can't seem to get at it.


XML
<?xml version="1.0" encoding="utf-8"?>
<kmsg xmlns:env="http://xml.kerridgecs.net/K809/k8msgEnvelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xml.kerridgecs.net/k8msg" xsi:schemaLocation="http://xml.kerridgecs.net/k8msg K8Invoice.xsd">
  <header>
    <env:envelope>
      <env:source branch="DEFAULT" endpoint="suppNum" machine="0" password="Toast" />
      <env:destination branch="0009" endpoint="01" machine="0" />
      <env:payload>INVOICE</env:payload>
      <env:cfcompany>01</env:cfcompany>
      <env:service>NOTSET</env:service>
    </env:envelope>
  </header>
  <body>
    <Invoice xmlns="urn:schemas-basda-org:2000:salesInvoice:xdr:3.01">
      <InvoiceReferences>
        <BuyersOrderNumber>1003164</BuyersOrderNumber>
      </InvoiceReferences>
    </Invoice>
  </body>
</kmsg>


I have taken a copy of the current stylesheet that is working, (I may have missed a couple of nodes during tidying up to ask this question, apologies)
XML
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version='1.0'  xmlns:HB='urn:schemas-basda-org:2001:eBUILD:1.00' xmlns:si='urn:schemas-basda-org:2000:salesInvoice:xdr:3.01' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:env="http://xml.kerridgecs.net/K809/k8msgEnvelope">
  <xsl:output encoding='iso-8859-1' method='html' />


	<xsl:variable name="document-version">
		Testing
	</xsl:variable>

  <xsl:template match='/'>
    <html>
      <head>
		<!-- Define the title (seen in the browser title bar-->
		<title><xsl:copy-of select="$document-version" /></title>
      </head>
      <body>
			<table width='100%'>
				<tr>				
					<td style='font-family:verdana;font-size:10pt;color:navy;text-align:right;font-weight:bold'>
						DESTINATION BRANCH<br><font size='5'>I WANT THE BRANCH NUMBER TO APPEAR HERE</font></br>
					</td>
				</tr>
				<tr style='height:10'>
					<td></td>
					<td></td>
				</tr>
			</table>
        <xsl:apply-templates select='//si:Invoice' />
      </body>
    </html>
  </xsl:template>
  <xsl:template match='si:Invoice'>
    <table>
     <tr>
        <td>
          <table>
            <tr>
             <td>
                <xsl:value-of select='si:InvoiceReferences/si:BuyersOrderNumber' />
                <xsl:if test='not(string-length(si:InvoiceReferences/si:BuyersOrderNumber))'>
                  <div class='warn'>Missing essential data.</div>
                </xsl:if>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </xsl:template>
</xsl:stylesheet>


What I have tried:

I have tried a few combinations, I have looked for namespace, (I suspect this would be the answer...), added
XML
xmlns:env="http://xml.kerridgecs.net/K809/k8msgEnvelope"
then tried
XML
<xsl:value-of select='env:destination/@branch' />
or
XML
<xsl:value-of select='env:envelope/env:destination/@branch' />


I have tried going to the full path...
XML
<xsl:value-of select='/kmsg/header/env:envelope/env:destination/@branch' />

Obviously I am missing something. All help appreciated and thanks in advance.
Posted
Updated 13-Aug-18 6:38am

1 solution

Just tried this and it is working...
XML
<xsl:value-of select='//env:destination/@branch'/>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900