누군가가 도울 수 있기를 바랍니다. 알아낼 수 없으며, 아마도 수행 할 수 없기를 바랍니다.XSLT를 사용하여 XML 부모 요소 특성 업데이트
다음 XML이 있으며 Document 요소의 조건에 따라 RedressNumber 및 KnownTravelerNumber를 업데이트해야합니다. 다음 XSLT를 사용하고 있지만 작동하지 않습니다.
DocTypeCode 조건이 true가 아닌 경우 속성을 그대로 복사해야합니다. 조건이 true이면 속성 값을 DocID 값으로 대체해야합니다.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="identity.xsl" />
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" encoding="UTF-8" />
<xsl:template match="ProfileRead">
<xsl:apply-imports />
</xsl:template>
<xsl:template match="ProfileRead/Profile/Traveler/Customer">
<xsl:copy>
<xsl:for-each select="Document">
<xsl:if test="@DocTypeCode = 'KTID'">
<xsl:attribute name="KnownTravelerNumber">
<xsl:value-of select="@DocID"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@DocTypeCode = 'RDNR'">
<xsl:attribute name="RedressNumber">
<xsl:value-of select="@DocID"/>
</xsl:attribute>
</xsl:if>
</xsl:for-each>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ProfileRead/Profile/Traveler/Customer/@KnownTravelerNumber" />
<xsl:template match="ProfileRead/Profile/Traveler/Customer/@RedressNumber" />
<!-- remove element -->
<xsl:template match="ProfileRead/Profile/Traveler/Customer/Document[@DocTypeCode='KTID']" />
<xsl:template match="ProfileRead/Profile/Traveler/Customer/Document[@DocTypeCode='RDNR']" />
</xsl:stylesheet>
<ProfileRead>
<Profile>
<Traveler>
<Customer GenderCode="M" RedressNumber="321" KnownTravelerNumber="123">
<PersonName LanguageIDCode="EN-US">
<GivenName>John</GivenName>
<MiddleName>Long</MiddleName>
<SurName>Smith</SurName>
<NameSuffix>Junior</NameSuffix>
</PersonName>
<Document DocID="666" DocTypeCode="RDNR" />
<Document DocID="111" DocTypeCode="KAMAL" />
<Document DocID="222" DocTypeCode="FRANK" />
</Customer>
</Traveler>
</Profile>
</ProfileRead>
정확히 내가 달성해야하는 것. 도와 주셔서 감사합니다. –
그러면 답을 받아 들일 수있게 해줘서 고맙다. –