如果HeaderInformation/InvoiceType = CreditNote,我如何中止xslt转换?
XML:
<?xml version="1.0" encoding="utf-8"?>
<SALESINVOICE>
<Interchange>
<Recipient>1234</Recipient>
<Sender>5678</Sender>
<CreationDate>2019-01-11:09:16:43</CreationDate>
<Test>No</Test>
<Interchange_Control_Number>123584</Interchange_Control_Number>
<HeaderInformation>
<OrigInvoiceNumber>1</OrigInvoiceNumber>
<InvoiceType>CreditNote</InvoiceType>
</HeaderInformation>
</Interchange>
</SALESINVOICE>
向Julian致以最好的问候
发布于 2019-01-16 18:15:54
根据你所说的“中止”的意思:
您可以像这样使用<xsl:message>:
<xsl:if test="HeaderInformation/InvoiceType='CreditNote'">
<xsl:message terminate="yes"/>
</xsl:if>这将终止,并显示一个错误。
如果你不想要一个错误,你也可以这样做:
<xsl:template match="/">
<xsl:if test="SALESINVOICE[not(Interchange/HeaderInformation/InvoiceType='CreditNote')]">
<!-- Here goes your XSLT code -->
<xsl:apply-templates/>
</xsl:if>
</xsl:template>如果找到值为CreditNote的<InvoiceType>,这将输出一个空文档。
发布于 2019-01-16 18:18:56
这里有一种方法(在许多方法中):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="SALESINVOICE[not(Interchange/HeaderInformation/InvoiceType='CreditNote')]"/>
</xsl:template>
<xsl:template match="SALESINVOICE">
<!-- instructions to process the invoice -->
</xsl:template>
</xsl:stylesheet>https://stackoverflow.com/questions/54214565
复制相似问题