gpt4 book ai didi

xml - 如何仅在包含具有特定属性值和元素值的子元素的元素上应用XSL模板?

转载 作者:行者123 更新时间:2023-12-03 16:23:02 24 4
gpt4 key购买 nike

我有以下XML(部分)文档:

<export>
<table name="CLIENT">
<row>
<col name="CODE_CLIENT" type="System.String">1000010026</col>
<col name="LIBELLE" type="System.String">Test|</col>
<col name="PROSPECT" type="System.Decimal">1</col>
</row>
<row>
<col name="CODE_CLIENT" type="System.String">1000010025</col>
<col name="LIBELLE" type="System.String">Rue de la 2eme ad|</col>
<col name="PROSPECT" type="System.Decimal">0</col>
</row>
<row>
<col name="CODE_CLIENT" type="System.String">1000010125</col>
<col name="LIBELLE" type="System.String">Test4</col>
<col name="PROSPECT" type="System.Decimal">0</col>
</row>
<row>
<col name="CODE_CLIENT" type="System.String">1000010035</col>
<col name="LIBELLE" type="System.String">Rue</col>
<col name="PROSPECT" type="System.Decimal">1</col>
</row>
</table></export>


和以下XSL:

<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates select="export/table[@name='CLIENT']"/>

</xsl:template>

<xsl:template match="row">
SOME TEMPLATE CODE

</xsl:template>


</xsl:stylesheet>


我只想将第一个模板(match =“ /”)应用于预期值为1的“行”。在我的示例中,这只会转换第一行和最后一行。

我试过了

<xsl:apply-templates select="export/table[@name='CLIENT']/row[col[@name='PROSPECT']=1]"/>


但这给了我一个语法错误。

有人知道如何进行吗?

最佳答案

我的建议:

<xsl:stylesheet 
version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:output method="text" indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates select="export/table[@name='CLIENT']"/>
</xsl:template>

<xsl:template match="table">
<xsl:apply-templates select="row[col[@name='PROSPECT' and text() = '1']]" />
</xsl:template>

<xsl:template match="row">
SOME TEMPLATE CODE
</xsl:template>

</xsl:stylesheet>


尽管您尝试:

<xsl:apply-templates select="
export/table[@name='CLIENT']/row[col[@name='PROSPECT']=1]
"/>


应该也能正常工作(虽然不那么明显,但是它本身并没有错)。不知道为什么它对您不起作用。

关于xml - 如何仅在包含具有特定属性值和元素值的子元素的元素上应用XSL模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1322635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com