gpt4 book ai didi

xml - XSLT 包含错误

转载 作者:数据小太阳 更新时间:2023-10-29 02:40:05 27 4
gpt4 key购买 nike

对于粗略的解释,我深表歉意,我对 xml 和 xslt 还很陌生。感谢您的耐心等待。

这是一个挑战,我正在尝试构建到 csv 的转换,为员工福利注册的每个实例创建一个新行。因此,如果他们参加了两个计划,则会为每个计划创建一条线路。他们的家属也在做同样的事情。
使用我的 xml,我如何遍历不同的节点并选择正确的数据?

在尝试确保我不会为未参加福利的家属制作线路时,我遇到了这个错误:

描述:XPTY0004:不允许将多个项目的序列作为 contains()(“System_ID”、“Dependent_ID”、...)的第一个参数

我看到 Dependent 元素中有不止一种 ID 类型,但我不想指定使用哪一种,因为我需要同时扫描它们。

这是我的 xml:

<Report>
<Employee_ID>111111</Employee_ID>
<Last_Name>Allen</Last_Name>
<First_Name>Amy</First_Name>
<Benefit_Elections>
<Benefit_Type>Accident</Benefit_Type>
<Coverage>Employee + Family</Coverage>
<Enrolled_Worker Descriptor="Amy Allen (111111)">
<ID type="System_ID">aaaaaa</ID>
<ID type="Employee_ID">111111</ID>
</Enrolled_Worker>
<Benefit_Plan Descriptor="Accident">
<ID type="System_ID">121212</ID>
<ID type="Health_Care_ID">hcp01</ID>
</Benefit_Plan>
<Covered_Dependents Descriptor="Sally Allen">
<ID type="System_ID">bbbbbb</ID>
<ID type="Dependent_ID">22222</ID>
</Covered_Dependents>
<Covered_Dependents Descriptor="Bob Allen">
<ID type="System_ID">ffffff</ID>
<ID type="Dependent_ID">44444</ID>
</Covered_Dependents>
</Benefit_Elections>
<Benefit_Elections>
<Benefit_Type>Critical Illness</Benefit_Type>
<Coverage>$10,000</Coverage>
<Calculated_Coverage>$10,000</Calculated_Coverage>
<Enrolled_Worker Descriptor="Amy Allen (111111)">
<ID type="System_ID">aaaaaa</ID>
<ID type="Employee_ID">111111</ID>
</Enrolled_Worker>
<Benefit_Plan
Descriptor="Critical Illness (Child)">
<ID type="System_ID">ssssss</ID>
<ID type="Insurance_Coverage_Plan_ID">icpchild</ID>
</Benefit_Plan>
<Covered_Dependents Descriptor="Sally Allen">
<ID type="System_ID">bbbbbb</ID>
<ID type="Dependent_ID">22222</ID>
</Covered_Dependents>
</Benefit_Elections>
<Benefit_Elections>
<Benefit_Type>Critical Illness</Benefit_Type>
<Coverage>$15,000</Coverage>
<Calculated_Coverage>$15,000</Calculated_Coverage>
<Enrolled_Worker Descriptor="Amy Allen (111111)">
<ID type="System_ID">aaaaaa</ID>
<ID type="Employee_ID">111111</ID>
</Enrolled_Worker>
<Benefit_Plan
Descriptor="Critical Illness (Spouse)">
<ID type="System_ID">tttttt</ID>
<ID type="Insurance_Coverage_Plan_ID">icpspouse</ID>
</Benefit_Plan>
<Covered_Dependents Descriptor="Bob Allen">
<ID type="System_ID">ffffff</ID>
<ID type="Dependent_ID">44444</ID>
</Covered_Dependents>
</Benefit_Elections>
<Benefit_Elections>
<Benefit_Type>Critical Illness</Benefit_Type>
<Coverage>$30,000</Coverage>
<Calculated_Coverage>$30,000</Calculated_Coverage>
<Enrolled_Worker Descriptor="Amy Allen (111111)">
<ID type="System_ID">aaaaaa</ID>
<ID type="Employee_ID">111111</ID>
</Enrolled_Worker>
<Benefit_Plan
Descriptor="Critical Illness (Employee)">
<ID type="System_ID">uuuuuu</ID>
<ID type="Insurance_Coverage_Plan_ID">icpemployee</ID>
</Benefit_Plan>
</Benefit_Elections>
<Dependents>
<First_Name>Sally</First_Name>
<Last_Name>Allen</Last_Name>
<Relationship Descriptor="Child">
<ID type="Related_Person_Relationship_ID">Child</ID>
</Relationship>
<Dependent_ID Descriptor="Sally Allen">
<ID type="System_ID">bbbbbb</ID>
<ID type="Dependent_ID">22222</ID>
</Dependent_ID>
</Dependents>
<Dependents>
<First_Name>Bob</First_Name>
<Last_Name>Allen</Last_Name>
<Relationship Descriptor="Spouse">
<ID type="Related_Person_Relationship_ID">Spouse</ID>
</Relationship>
<Uses_Tobacco>0</Uses_Tobacco>
<Dependent_ID Descriptor="Bob Allen">
<ID type="System_ID">ffffff</ID>
<ID type="Dependent_ID">44444</ID>
</Dependent_ID>
</Dependents>
</Report>

这是我的 xslt:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="/">
<xsl:for-each select="Report">
<Record>
<xsl:call-template name="EmployeeData"/>
<xsl:for-each select="Dependents">
<xsl:call-template name="Print_Dependents">
<xsl:with-param name="BenefitsExtractEmployeeNode" select=".."/>
</xsl:call-template>
</xsl:for-each>
</Record>
</xsl:for-each>
</xsl:template>
<xsl:template name="EmployeeData">
<First_Name><xsl:value-of select="First_Name"/></First_Name>
<Last_Name><xsl:value-of select="Last_Name"/></Last_Name>
<Benefit_Type><xsl:value-of select="Benefit_Elections/Benefit_Type"/></Benefit_Type>
<Coverage><xsl:value-of select="Benefit_Elections/Coverage"/></Coverage>
<Calculated_Coverage><xsl:value-of select="Benefit_Elections/Calculated_Coverage"/></Calculated_Coverage>
</xsl:template>
<xsl:template name="Print_Dependents">
<xsl:param name="BenefitsExtractEmployeeNode"/>
<xsl:if test="contains($BenefitsExtractEmployeeNode/Benefit_Elections/Covered_Dependents[ID/@type ='Dependent_ID']/ID/@type,
Dependents/Dependent_ID[ID/@type='Dependent_ID']/ID/@type)">
<Dependent>
<First_Name><xsl:value-of select="Dependents/First_Name"/></First_Name>
<Last_Name><xsl:value-of select="Dependents/Last_Name"/></Last_Name>
<Benefit_Type><xsl:value-of select="$BenefitsExtractEmployeeNode/Benefit_Elections/Benefit_Type"/></Benefit_Type>
<Coverage><xsl:value-of select="$BenefitsExtractEmployeeNode/Benefit_Elections/Coverage"/></Coverage>
<Calculated_Coverage><xsl:value-of select="$BenefitsExtractEmployeeNode/Benefit_Elections/Calculated_Coverage"/></Calculated_Coverage>
</Dependent>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

最佳答案

如果没有所需输出的示例,很难确切地说出您正在尝试做什么(您提到转换为 CSV,但您的 XSLT 正在输出 XML)。

但是,您应该能够将 contains() 移动到 xsl:if 测试中的 ID 元素...

    <xsl:if test="$BenefitsExtractEmployeeNode/Benefit_Elections/Covered_Dependents[
ID/@type ='Dependent_ID']/ID[contains(@type,
Dependents/Dependent_ID[ID/@type='Dependent_ID']/ID/@type)]">
...
</xsl:if>

关于xml - XSLT 包含错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30533652/

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