我有以下XML:
...
<peci:Address peci:isDeleted="1">
<peci:Usage_Type>WORK</peci:Usage_Type>
<peci:Address_Line_1>AMEC</peci:Address_Line_1>
<peci:Address_Line_2>2020 Winston Park Drive, Suite
700</peci:Address_Line_2>
<peci:City>Oakville</peci:City>
<peci:Postal_Code>L6H 6X7</peci:Postal_Code>
<peci:Country>CA</peci:Country>
<peci:Country_Region>ON</peci:Country_Region>
<peci:State_Province>Ontario</peci:State_Province>
</peci:Address>
<peci:Address peci:isAdded="1">
<peci:Usage_Type>WORK</peci:Usage_Type>
<peci:Address_Line_1>639 5th Avenue SW</peci:Address_Line_1>
<peci:Address_Line_2>Suite 1410</peci:Address_Line_2>
<peci:City>Calgary</peci:City>
<peci:Postal_Code>T2P 0M9</peci:Postal_Code>
<peci:Country>CA</peci:Country>
<peci:Country_Region>AB</peci:Country_Region>
<peci:State_Province>Alberta</peci:State_Province>
<peci:Address>
<peci:Usage_Type>HOME</peci:Usage_Type>
<peci:Address_Line_1>88 Bridge Cres.</peci:Address_Line_1>
<peci:City>Burlington</peci:City>
<peci:Postal_Code>L7L 0A3</peci:Postal_Code>
<peci:Country>CA</peci:Country>
<peci:Country_Region>ON</peci:Country_Region>
<peci:State_Province>Ontario</peci:State_Province>
</peci:Address>
<peci:Email/>
...
i通过文档进行迭代,当找到添加节点
时peci:isAdded="1"
我检查主持节点是否具有相同的元素并已删除
peci:isDeleted="1"
如果是这种情况
我想将其用于不同的节点,因此我无法使用硬编码元素列表,当迭代添加元素时,我不知道如何访问程序同级中的相应元素。它尝试sth喜欢:
<xsl:when
test="../@peci:isAdded and ../preceding-sibling::*[../local-name()]/@peci:isDeleted">
<xsl:variable name="oldValueLocations" select="local-name()"/>
<xsl:value-of select="../preceding-sibling::*[../local-name()][@peci:isDeleted]/$oldValueLocations"/>
</xsl:when>
我期望
<out:Row xtt:separator="," xtt:quotes="always">
<out:PayGroupCode>93JH</out:PayGroupCode>
<out:LegacyID>93JH000660265</out:LegacyID>
<out:WorkdayID>660265</out:WorkdayID>
<out:Name>SixWFNLastname SixWFNFirstname</out:Name>
<out:Status>Active</out:Status>
<out:Transaction>CHANGE</out:Transaction>
<out:Process_Type>DTA</out:Process_Type>
<out:Type>Address</out:Type>
<out:SubType>Country_Region</out:SubType>
<out:Effective_Date>2017-03-06</out:Effective_Date>
<out:Old_Value>ON</out:Old_Value>
<out:New_Value>AB</out:New_Value>
</out:Row>
但是我得到
<out:Row xtt:separator="," xtt:quotes="always">
<out:PayGroupCode>93JH</out:PayGroupCode>
<out:LegacyID>93JH000660265</out:LegacyID>
<out:WorkdayID>660265</out:WorkdayID>
<out:Name>SixWFNLastname SixWFNFirstname</out:Name>
<out:Status>Active</out:Status>
<out:Transaction>CHANGE</out:Transaction>
<out:Process_Type>DTA</out:Process_Type>
<out:Type>Address</out:Type>
<out:SubType>Country_Region</out:SubType>
<out:Effective_Date>2017-03-06</out:Effective_Date>
<out:Old_Value>WORK AMEC 2020 Winston Park Drive, Suite 700 Oakville L6H 6X7 CA ON
Ontario</out:Old_Value>
<out:New_Value>AB</out:New_Value>
</out:Row>
如果您知道local-name()
和谓词,选择*[local-name() = $oldValueLocations]
似乎很明显,可以选择该名称的元素,可能在您的其他路径上都有前缀(尽管我不了解[../local-name()]
应该是什么做)。