为什么XSL:变量节点don´;我的XML文件中没有显示?
我有下一个代码:为什么XSL:变量节点don´;我的XML文件中没有显示?,xml,xslt,xpath,xslt-1.0,Xml,Xslt,Xpath,Xslt 1.0,我有下一个代码: <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cfd="http://www.sat.gob.mx/cfd/2" xmlns:ecc="http://www.sat.gob.mx/cfd/2" xmlns:fo="http://www.w3.org/1
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cfd="http://www.sat.gob.mx/cfd/2" xmlns:ecc="http://www.sat.gob.mx/cfd/2" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" version="1.0" indent="yes" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:element name="Addenda">
<xsl:element name="requestForPayment">
<xsl:attribute name="type">SimpleInvoiceType</xsl:attribute>
<xsl:attribute name="contentVersion">1.3.1</xsl:attribute>
<xsl:attribute name="documentStructureVersion">AMC7.1</xsl:attribute>
<xsl:attribute name="documentStatus">ORIGINAL</xsl:attribute>
<xsl:attribute name="DeliveryDate">
<xsl:value-of select="substring(translate(//DocDate, ' ', ''),1,10)"/>
</xsl:attribute>
<xsl:element name="requestForPaymentIdentification">
<xsl:element name="entityType">
<xsl:call-template name="Tpos_Documento"/>
</xsl:element>
<xsl:element name="uniqueCreatorIdentification">
<xsl:value-of select="concat(//Serial/Name,//Serial/Folio)"/>
</xsl:element>
</xsl:element>
<xsl:variable name="zzz_specialInstruction" select="count(//CustomField[@name = 'Text3']/StringValue)"/>
<xsl:if test="$zzz_specialInstruction > 0">
<xsl:element name="specialInstruction">
<xsl:attribute name="code">ZZZ</xsl:attribute>
<xsl:element name="text">
<xsl:value-of select="//CustomField[@name = 'Text3']/StringValue"/>
</xsl:element>
</xsl:element>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
SimpleInvoiceType
1.3.1
AMC7.1
起初的
ZZZ
但是下一个节点不会出现在my XML generate中:
<xsl:variable name="zzz_specialInstruction" select="count(//CustomField[@name = 'Text3']/StringValue)"/>
<xsl:if test="$zzz_specialInstruction > 0">
<xsl:element name="specialInstruction">
<xsl:attribute name="code">ZZZ</xsl:attribute>
<xsl:element name="text">
<xsl:value-of select="//CustomField[@name = 'Text3']/StringValue"/>
</xsl:element>
</xsl:element>
</xsl:if>
ZZZ
我的问题是,当我编译XSLT的代码时,它的节点没有出现。My dude就是为什么不在我的XML文件中显示此节点的原因。???
xsl:variable
元素为所创建变量的给定名称分配一个值。就像在下面的python代码中,x=3*3
,如果没有这样的print语句,数字将无法打印:
x = 3*3
print x
# Displays 9 on the screen.
同样,在XSLT中,这是:
<xsl:variable name="x" select="3*3" />
什么也不做。在输出XML文件中生成该文件的唯一方法是执行一个命令,该命令将在输出中呈现该文件,如下所示:
<xsl:variable name="x" select="3*3" />
<xsl:element name="x">
<xsl:value select="$x"/>
</xsl:element>
这将产生:
<x>9</x>
9
您是否意识到,您可以将其写得更通俗易懂:
<xsl:template match="/">
<Addenda>
<requestForPayment
type="SimpleInvoiceType"
contentVersion="1.3.1"
documentStructureVersion="AMC7.1"
documentStatus="ORIGINAL"
DeliveryDate="{substring(translate(//DocDate, ' ', ''),1,10)}">
<requestForPaymentIdentification>
<entityType>
<xsl:call-template name="Tpos_Documento"/>
</entityType>
<uniqueCreatorIdentification>
<xsl:value-of select="concat(//Serial/Name,//Serial/Folio)"/>
</uniqueCreatorIdentification>
</requestForPaymentIdentification >
<xsl:variable name="zzz_specialInstruction"
select="count(//CustomField[@name = 'Text3']/StringValue)"/>
<xsl:if test="$zzz_specialInstruction > 0">
<specialInstruction code="ZZZ">
<text>
<xsl:value-of select="//CustomField[@name = 'Text3']/StringValue"/>
</text>
</specialInstruction >
</xsl:if>
...
</xsl:template>
...
我们可能需要一些输入XML。但总的来说。。。如果您问为什么xsl:value没有显示在生成的XML中,那是因为它是一个xsl变量,而不是一个输出模板