本文介绍了如何在每个XSLT中读取外部元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的专业人士,下面我提到了xml文件



Dear Professional, below i have mentioned xml file

<Quote>
  <Table>
    <OrganisationId>1</OrganisationId>
    <OrganisationName>its</OrganisationName>
    <CustomerId>1</CustomerId>
    <CustomerFirstName>Nixon</CustomerFirstName>
    <CustomerMiddleName />
    <CustomerLastName>A</CustomerLastName>
    <CustomerEmail>[email protected]</CustomerEmail>
    <OrganisationAddress>TEST</OrganisationAddress>
    <City>BANG</City>
    <Country>India</Country>
    <PostalCode>566</PostalCode>
  </Table>
  <Table1>
    <QuoteId>1</QuoteId>
    <CustomerId>1</CustomerId>
    <Currency>GBP</Currency>
    <CustomerType>End-User</CustomerType>
    <EndUserName />
    <QuoteCost>3500.00</QuoteCost>
    <Description>Added Temp</Description>
    <Status>false</Status>
    <TemplateId>1</TemplateId>
  </Table1>
  <Table2>
    <QuoteDtlId>2</QuoteDtlId>
    <Product>MYPC-ADD-5</Product>
    <ProductGroup>MyPC Purchase</ProductGroup>
    <Description>MyPC Licence for 5 Computers</Description>
    <ExtendedDescription>Blah Blah</ExtendedDescription>
    <CostPrice>30.00</CostPrice>
    <SellPrice>300.00</SellPrice>
    <Quantity>1</Quantity>
    <Selected>true</Selected>
    <Maintenance>false</Maintenance>
    <MaintenanceId>0</MaintenanceId>
    <Total>300.00</Total>
    <TaxPolicy>Standard</TaxPolicy>
    <AccountingCode>A030</AccountingCode>
    <QuoteId>1</QuoteId>
  </Table2>
  <Table2>
    <QuoteDtlId>3</QuoteDtlId>
    <Product>MYPC-BASE</Product>
    <ProductGroup>MyPC Purchase</ProductGroup>
    <Description>MyPC Base Licence Includes: Centralised Database. Internet / Intranet Booking. Library Fines and Overdue Items Module. Full Documentation and Reference Guides. Installation and Training (including all expenses). </Description>
    <ExtendedDescription>Blah Blah</ExtendedDescription>
    <CostPrice>320.00</CostPrice>
    <SellPrice>3200.00</SellPrice>
    <Quantity>1</Quantity>
    <Selected>false</Selected>
    <Maintenance>false</Maintenance>
    <MaintenanceId>0</MaintenanceId>
    <Total>3200.00</Total>
    <TaxPolicy>Standard</TaxPolicy>
    <AccountingCode>A030</AccountingCode>
    <QuoteId>1</QuoteId>
  </Table2>
  <Table3>
    <TemplateType>text</TemplateType>
    <TemplateHtml>&lt;p&gt;AAAAAAAA&lt;br data-mce-bogus="1"&gt;&lt;/p&gt;</TemplateHtml>
  </Table3>
  <Table3>
    <TemplateType>text</TemplateType>
    <TemplateHtml>&lt;p&gt;cccccccccccccccc&lt;br data-mce-bogus="1"&gt;&lt;/p&gt;</TemplateHtml>
  </Table3>
  <Table3>
    <TemplateType>pricing</TemplateType>
    <TemplateHtml />
  </Table3>
  <Table3>
    <TemplateType>pageBreak</TemplateType>
    <TemplateHtml />
  </Table3>
  <Table3>
    <TemplateType>text</TemplateType>
    <TemplateHtml>
      XXXXXXXXXXXXXXXXX
    </TemplateHtml>
  </Table3>
</Quote>





我的XSl文件是:



My XSl file is:

<xsl:for-each select="Quote/Table3">
   </xsl:for-each>





在我要阅读的每个声明中表1值..



在此先感谢..请帮助我。



Inside the for each statement i want to read Table1 values ..

Thanks In advance ..please help me .

推荐答案

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<Quote>
  <Table>





现在尝试这个xsl内容:



Now try this xsl content:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h1>Table2</h1>
  <table>
    <tr><th>QuoteDtlId</th><th>CostPrice</th><th>SellPrice</th><th>Total</th><th>Currency</th></tr>
    <xsl:for-each select="Quote/Table2">
    <tr>
    <td><xsl:value-of select="QuoteDtlId" /></td>
    <td><xsl:value-of select="CostPrice" /></td>
    <td><xsl:value-of select="SellPrice" /></td>
    <td><xsl:value-of select="Total" /></td>
    <!-- this element comes from outside a loop-->
    <td><xsl:value-of select="../Table1/Currency" /></td>
    </tr>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>







转换结果:




Result of conversion:

<html>
<body>
<h1>Table2</h1>
<table><tbody>
<tr><th>QuoteDtlId</th><th>CostPrice</th><th>SellPrice</th><th>Total</th><th>Currency</th>
<tr><td>2</td><td>30.00</td><td>300.00</td><td>300.00</td><td>GBP</td></tr>
<tr><td>3</td><td>320.00</td><td>3200.00</td><td>3200.00</td><td>GBP</td></tr>
</tbody>
</table>
</body>
</html>





Change it to your needs ;)



Change it to your needs ;)


这篇关于如何在每个XSLT中读取外部元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 14:11