gpt4 book ai didi

xml - 使用XSLT为每个空字段传递文本值

转载 作者:行者123 更新时间:2023-12-03 16:09:31 25 4
gpt4 key购买 nike

我用各种验证等创建了一个XSLT。现在我的客户希望我为每个空白值传递XXX。有很多字段,我不想为每个字段手动执行此操作。可以帮忙吗?以下是我的XSLT

(编辑和简化查询)

我的XML:

<?xml version="1.0" encoding="UTF-8"?>
<contract>
<customerName>foo</customerName>
<contractID />
<customerID>912</customerID>
<countryCode/>
<cityCode>7823</cityCode>
</contract>


XSLT:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>

<xsl:template match="/">
<xsl:value-of select="contract/customerName"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="contract/contractID"/>
</xsl:template>

</xsl:stylesheet>


我希望输出为foo | XXX(任何空白字段为XXX)

最佳答案

由于您似乎正在使用XSLT 2.0,因此我建议一种完全不同的方法。

这是产生结果标题部分的最小化示例:

XSLT 2.0

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wd="urn:com.workday/bsvc">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>

<xsl:template match="wd:Get_Workers_Response">
<!--Defining Header-->
<xsl:variable name="header-fields" select="
wd:Request_Criteria/wd:Organization_Reference/wd:ID[@wd:type='Organization_Reference_ID'],
wd:Response_Results/wd:Total_Results,
wd:Response_Results/wd:Total_Pages,
format-date(current-date(), '[M01][D01][Y0001]')" />
<xsl:value-of select="string-join(for $i in $header-fields return if (string($i)) then $i else 'XXX', '|')"/>
<xsl:text>&#xa;</xsl:text>
<!--Ending Header-->

<!-- ... continue for Employee Data and Footer ... -->
</xsl:template>

</xsl:stylesheet>


请注意,这假设“字段”可以为空,但不会丢失。

关于xml - 使用XSLT为每个空字段传递文本值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37893117/

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