Xslt 查找一系列值,并从xsl开始使用

Xslt 查找一系列值,并从xsl开始使用,xslt,range,between,Xslt,Range,Between,我需要询问Supplier_ID的范围是否在985000和989999之间,然后在tagAllocationNumber中设置值“FX”,否则让它为空 我想用start with xsl函数来解决这个问题 但它不起作用(我是XSL新手) C:\Program Files(x86)\MaxPostInvoice-v1.18.xsd 这是输入XML: <Form name="FP0001"> <Fields> <Supplier_ID con

我需要询问
Supplier_ID
的范围是否在985000和989999之间,然后在tag
AllocationNumber
中设置值“FX”,否则让它为空

我想用start with xsl函数来解决这个问题

但它不起作用(我是XSL新手)


C:\Program Files(x86)\MaxPostInvoice-v1.18.xsd
这是输入XML:

<Form name="FP0001">
    <Fields>
        <Supplier_ID contents="985000" rawContents="" source="OCR" confidence="100"/>
        <Supplier_Name contents="Leifheitstr" rawContents="" source="OCR" confidence="100"/>
        <Supplier_Street contents="abcde" rawContents="" source="OCR" confidence="100"/>
    </Fields>
</Form>

结果

您尚未提供输入XML,如果XPath正确,您可以执行以下操作:

<xsl:attribute name="rawValue">
    <xsl:if test="number(./Fields/Supplier_ID/@contents) &gt;= 985000 and number(./Fields/Supplier_ID/@contents) &lt;= 989999">
        <xsl:value-of select="FX"/>
    </xsl:if>
</xsl:attribute>
<xsl:attribute name="rawValue">
    <xsl:if test="number(./Fields/Supplier_ID/@contents) &gt;= 985000 and number(./Fields/Supplier_ID/@contents) &lt;= 989999">
        <xsl:value-of select="FX"/>
    </xsl:if>
</xsl:attribute>


如果它不起作用,请共享您的输入XML和更多XSLT(完整)。

为什么相同的属性有两次?在任何情况下,您都需要更改:

<xsl:value-of select="FX"/>

致:



顺便说一句,在我看来,你可以将这件事大大简化为:

<xsl:template match="/Form/Fields">
    <MaxPostInvoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Program Files (x86)\MaxPostInvoice-v1.18.xsd">
            <Header>
                <VendorID source="{Supplier_ID/@source}" confidence="{Supplier_ID/@confidence}" >
                    <xsl:attribute name="rawValue">
                        <xsl:if test="Supplier_ID/@rawContents != 'X'">
                            <xsl:value-of select="Supplier_ID/@rawContents"/>
                        </xsl:if>
                    </xsl:attribute>
                    <xsl:attribute name="value">
                        <xsl:if test="Supplier_ID/@contents != 'X'">
                            <xsl:value-of select="Supplier_ID/@contents"/>
                        </xsl:if>
                    </xsl:attribute>
                </VendorID>
                <AllocationNumber>
                    <xsl:attribute name="rawValue">
                        <xsl:if test="number(Supplier_ID/@contents) &gt;= 985000 and number(Supplier_ID/@contents) &lt;= 989999">
                            <xsl:value-of select="'FX'"/>
                        </xsl:if>
                    </xsl:attribute>
                </AllocationNumber>
            </Header>
     </MaxPostInvoice>
</xsl:template>


这取决于您所在节点的上下文。您能显示您的输入XML文件吗?还有一个更详细的xsl,它是模板匹配吗?还要考虑到测试第一个数字与检查数字是否在范围内是不同的。请不要在注释中发布代码,而是编辑您的问题。同时发布一个完整的样式表。它不一定是你的整个样式表,但它应该是完整的,因为我们可以直接运行它,并看到问题所在。其中一个很有价值,很有效。这就是我要找的!大的Thanks@user3702725如果有效,请通过接受答案来结束此问题。
<xsl:value-of select="'FX'"/>
<xsl:template match="/Form/Fields">
    <MaxPostInvoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Program Files (x86)\MaxPostInvoice-v1.18.xsd">
            <Header>
                <VendorID source="{Supplier_ID/@source}" confidence="{Supplier_ID/@confidence}" >
                    <xsl:attribute name="rawValue">
                        <xsl:if test="Supplier_ID/@rawContents != 'X'">
                            <xsl:value-of select="Supplier_ID/@rawContents"/>
                        </xsl:if>
                    </xsl:attribute>
                    <xsl:attribute name="value">
                        <xsl:if test="Supplier_ID/@contents != 'X'">
                            <xsl:value-of select="Supplier_ID/@contents"/>
                        </xsl:if>
                    </xsl:attribute>
                </VendorID>
                <AllocationNumber>
                    <xsl:attribute name="rawValue">
                        <xsl:if test="number(Supplier_ID/@contents) &gt;= 985000 and number(Supplier_ID/@contents) &lt;= 989999">
                            <xsl:value-of select="'FX'"/>
                        </xsl:if>
                    </xsl:attribute>
                </AllocationNumber>
            </Header>
     </MaxPostInvoice>
</xsl:template>