从XML获取属性 [英] Getting attribute from XML

查看:94
本文介绍了从XML获取属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

毫无疑问,对你来说很快就是专家,但对我而言,这是一个毫无结果的下午。

我有XML,我被要求进一步询问(减少以下版本.. 。)

我想要做的是输出各个部分并用html表示。我需要添加的是env:destination / @ branch。



但是我似乎无法理解它。





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 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已经拍摄了当前正在运行的样式表的副本,(我可能错过了几个节点) g整理问这个问题,道歉)



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 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

xmlns:env="http://xml.kerridgecs.net/K809/k8msgEnvelope"

然后尝试

<xsl:value-of select='env:destination/@branch' />

<xsl:value-of select='env:envelope/env:destination/@branch' />





我已经尝试了完整的路径...



I have tried going to the full path...

<xsl:value-of select='/kmsg/header/env:envelope/env:destination/@branch' />



明显我错过了一些东西。所有帮助表示感谢并提前感谢。


Obviously I am missing something. All help appreciated and thanks in advance.

推荐答案

document-version / > < / title >
< / head >
< 正文 >
< < span class =code-leadattribute> table width =' 100%' >
< tr >
< td style =' font-family:verdana; font-size:10pt; color:navy; text-align:right; font-weight:bold' >
DESTINATION BRANCH < br > < font < span class =code-attribute> size =' 5' > 我想要分支号码在此处出现< / font > < / br >
< / td >
< / tr >
< tr style =' height:10' >
< td > < / td >
< td > < / td >
< / tr >
< / table > ;
< xsl:apply-templates 选择 =' / / si:发票' / >
< / body >
< / html >
< / xsl:template >
< xsl:模板 匹配 =' si:发票' >
< 表格 >
< ; tr >
< td >
< table >
< tr >
< td >
< xsl:value-of 选择 =' si:InvoiceReferences / si:BuyersOrderNumber' / >
< xsl:if test =' not(字符串长度(si:InvoiceReferences) / SI:BuyersOrderNumber))' <跨度class =code-keyword>>
< div < span class =code-attribute>
class =' warn' > 缺少基本数据。< / div >
< / xsl:if >
< / td >
< / tr >
< / table >
< / td >
< / tr >
< / table >
< / xsl:template >
< / xsl:stylesheet >
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

xmlns:env="http://xml.kerridgecs.net/K809/k8msgEnvelope"

然后尝试

<xsl:value-of select='env:destination/@branch' />

<xsl:value-of select='env:envelope/env:destination/@branch' />





我已经尝试过完整的路径...



I have tried going to the full path...

<xsl:value-of select='/kmsg/header/env:envelope/env:destination/@branch' />



显然我错过了什么。所有的帮助表示感谢并提前感谢。


Obviously I am missing something. All help appreciated and thanks in advance.


试过这个,它正在运行...
Just tried this and it is working...
<xsl:value-of select='//env:destination/@branch'/>


这篇关于从XML获取属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆