«xsl: value-of» в XSLT не работает должным образом.Он вставляет значение для немногих и не для других полей - PullRequest
0 голосов
/ 03 октября 2018

У меня есть XML, который я хочу преобразовать с помощью XSLT.Я записал свой XSLT, чтобы выбрать определенный элемент XML (уникальный ключ) и добавить его к различным дочерним узлам, чтобы при вставке в MS Access все они оставались подключенными.Интересной частью является логика получения уникального ключа, скажем, <ReferenceNumber> в <Header> вставляется в несколько дочерних XML, но не во все из них.Ниже приведен XML

<PreciseIDServer>
<PIDXMLVersion>xcxc</PIDXMLVersion>
<SessionID>xc.xcx</SessionID>
<Header>
    <ReportDate>xc</ReportDate>
    <ReportTime>xcx</ReportTime>
    <ProductOption>cx</ProductOption>
    <Subcode>xcxc</Subcode>
    <ReferenceNumber>xcx</ReferenceNumber>
</Header>
<Summary>
    <TransactionID>xcx</TransactionID>
    <InitialDecision>xcx</InitialDecision>
    <FinalDecision>xc</FinalDecision>
    <CrossReferenceIndicatorsGrid>
        <FullNameVerifiesToAddress code="MA"/>
        <FullNameVerifiesToSSN code="MA"/>
        <FullNameVerifiesToDL code="NM"/>
        <FullNameVerifiesToPhone code="NM"/>
        <SurnameOnlyVerifiesToAddress code="NM"/>
        <SurnameOnlyVerifiesToSSN code="NM"/>
        <SurnameOnlyVerifiesToDL code="NM"/>
        <SurnameOnlyVerifiesToPhone code="NM"/>
        <AddressVerifiesToFullName code="MA"/>
        <AddressVerifiesToSurnameOnly code="NM"/>
        <AddressVerifiesToSSN code="MA"/>
        <AddressVerifiesToDL code="NM"/>
        <AddressVerifiesToPhone code="NM"/>
        <SSNVerifiesToFullName code="MA"/>
        <SSNVerifiesToSurnameOnly code="NM"/>
        <SSNVerifiesToAddress code="MA"/>
        <DLVerifiesToFullName code="NM"/>
        <DLVerifiesToSurnameOnly code="NM"/>
        <DLVerifiesToAddress code="NM"/>
        <PhoneVerifiesToFullName code="NM"/>
        <PhoneVerifiesToSurnameOnly code="NM"/>
        <PhoneVerifiesToAddress code="NM"/>
    </CrossReferenceIndicatorsGrid>
    <DateOfBirthMatch code="9"/>
</Summary>
<GLBDetail>
    <FraudShield>
        <Indicator code="01">N</Indicator>
        <Indicator code="02">N</Indicator>
        <Indicator code="03">N</Indicator>
        <Indicator code="04">N</Indicator>
        <Indicator code="05">N</Indicator>
        <Indicator code="06">N</Indicator>
        <Indicator code="10">N</Indicator>
        <Indicator code="11">N</Indicator>
        <Indicator code="13">N</Indicator>
        <Indicator code="14">N</Indicator>
        <Indicator code="15">N</Indicator>
        <Indicator code="16">N</Indicator>
        <Indicator code="17">N</Indicator>
        <Indicator code="18">N</Indicator>
        <Indicator code="21">N</Indicator>
        <Indicator code="25">N</Indicator>
        <Indicator code="26">N</Indicator>
    </FraudShield>
</GLBDetail>
<PreciseMatch>
    <Version>zx.zx</Version>
    <ResponseStatusCode code="00"/>
    <PreciseMatchTransactionID>zx-zx-zx-xz</PreciseMatchTransactionID>
    <PreciseMatchScore>zx</PreciseMatchScore>
    <PreciseMatchDecision code=" "/>
    <Addresses>
            <Address>
                <Summary>
                    <VerificationResult code="A1"/>
                    <Type code="S "/>
                    <UnitMismatchResult code="  "/>
                    <HighRiskResult code="N "/>
                    <Counts>
                        <StandardizedAddressReturnCount>xz</StandardizedAddressReturnCount>
                        <ResidentialAddressMatchCount>zx</ResidentialAddressMatchCount>
                        <ResidentialAddressReturnCount>zx</ResidentialAddressReturnCount>
                        <HighRiskAddressReturnCount>zx</HighRiskAddressReturnCount>
                        <BusinessAddressMatchCount>zx</BusinessAddressMatchCount>
                        <BusinessAddressReturnCount>zx</BusinessAddressReturnCount>
                    </Counts>
                </Summary>
                <Detail>
                    <StandardizedAddressRcd>
                        <Surname>xc</Surname>
                        <FirstName>xc</FirstName>
                        <Middle>cx</Middle>
                        <Address>cx xc xc</Address>
                        <City>xc</City>
                        <State>xc</State>
                        <ZipCode>xc</ZipCode>
                        <ZipPlus4>xc</ZipPlus4>
                    </StandardizedAddressRcd>
                    <ResidentialAddressRcd>
                        <Surname>xc</Surname>
                        <FirstName>xc</FirstName>
                        <Address>xc xc xc</Address>
                        <City>xc</City>
                        <State>xc</State>
                        <ZipCode>xc</ZipCode>
                        <ZipPlus4>xc</ZipPlus4>
                    </ResidentialAddressRcd>
                    <ResidentialAddressRcd>
                        <Surname>xc</Surname>
                        <FirstName>xc</FirstName>
                        <Middle>xc</Middle>
                        <Address>xc xc xc</Address>
                        <City>xc</City>
                        <State>xc</State>
                        <ZipCode>c</ZipCode>
                        <ZipPlus4>xc</ZipPlus4>
                        <AreaCode>xc</AreaCode>
                        <Phone>xc</Phone>
                        <OtherHouseholdMembers>
                        <Name>xc zx</Name>
                        <Name>zx</Name>
                        </OtherHouseholdMembers>
                        <MonthsAtResidence>xc</MonthsAtResidence>
                        <LastUpdatedDate>xc</LastUpdatedDate>
                    </ResidentialAddressRcd>
                    <ResidentialAddressRcd>
                        <Surname>zx</Surname>
                        <FirstName>zx</FirstName>
                        <Address>zx zx zx</Address>
                        <City>zx</City>
                        <State>zx</State>
                        <ZipCode>zx</ZipCode>
                        <ZipPlus4>zx</ZipPlus4>
                    </ResidentialAddressRcd>
                    <ResidentialAddressRcd>
                        <Surname>zx</Surname>
                        <FirstName>zx</FirstName>
                        <Middle>zx</Middle>
                        <Address>zx zx zx</Address>
                        <City>zx</City>
                        <State>zx</State>
                        <ZipCode>zx</ZipCode>
                        <ZipPlus4>zx</ZipPlus4>
                    </ResidentialAddressRcd>
                    <HighRiskAddressRcd>
                        <BusinessName>zx zx zx</BusinessName>
                        <Address>zx zx zx</Address>
                        <City>zx</City>
                        <State>zx</State>
                        <ZipCode>zx</ZipCode>
                        <ZipPlus4>zx</ZipPlus4>
                        <AreaCode>zx</AreaCode>
                        <Phone>zx</Phone>
                    </HighRiskAddressRcd>
                    <HighRiskAddressDescription>
                        <HighRiskDescription>zx &amp; zx</HighRiskDescription>
                    </HighRiskAddressDescription>
                </Detail>
            </Address>
    </Addresses>
    <Phones>
        <Phone>
            <Summary>
                <VerificationResult code="MX"/>
                <Classification code="X"/>
                <HighRiskResult code="N"/>
                <Counts>
                    <ResidentialPhoneMatchCount>zx</ResidentialPhoneMatchCount>
                    <ResidentialPhoneReturnCount>zx</ResidentialPhoneReturnCount>
                    <HighRiskPhoneReturnCount>zx</HighRiskPhoneReturnCount>
                    <BusinessPhoneMatchCount>zx</BusinessPhoneMatchCount>
                    <BusinessPhoneReturnCount>zx</BusinessPhoneReturnCount>
                </Counts>
            </Summary>
            <Detail>
                <HighRiskPhoneDescription>
                    <HighRiskDescription>zx zx zx zx zx zx/zx</HighRiskDescription>
                </HighRiskPhoneDescription>
            </Detail>
        </Phone>
    </Phones>
    <ConsumerID>
        <Summary>
            <VerificationResult code="YA"/>
            <DeceasedResult code="N"/>
            <FormatResult code="V"/>
            <IssueResult code="I"/>
            <IssueState>zx</IssueState>
            <IssueStartRange>zx</IssueStartRange>
            <IssueEndRange>zx</IssueEndRange>
            <Counts>
                <ConsumerIDReturnCount>zx</ConsumerIDReturnCount>
            </Counts>
        </Summary>
        <Detail>
            <ConsumerIDRcd>
                <Surname>zx</Surname>
                <FirstName>zx</FirstName>
                <Address>zx zx zx</Address>
                <City>x</City>
                <State>zx</State>
                <ZipCode>zx</ZipCode>
                <ZipPlus4>zx</ZipPlus4>
                <ReportedDate>zx</ReportedDate>
                <LastUpdatedDate>zx</LastUpdatedDate>
            </ConsumerIDRcd>
        </Detail>
    </ConsumerID>
    <DateOfBirth>
        <Summary>
            <MatchResult code="9"/>
            <MonthOfBirth>xz</MonthOfBirth>
            <DayOfBirth>zx</DayOfBirth>
            <YearOfBirth>zx</YearOfBirth>
        </Summary>
    </DateOfBirth>
    <DriverLicense/>
    <ChangeOfAddresses>
        <ChangeOfAddress>
            <Summary>
                <VerificationResult code="C "/>
                <Counts>
                    <ChangeOfAddressReturnCount>zx</ChangeOfAddressReturnCount>
                </Counts>
            </Summary>
            <Detail>
                <ChangeOfAddressRcd>
                    <Name>zx zx zx</Name>
                    <Address>zx zx zx</Address>
                    <City>zx</City>
                    <State>zx</State>
                    <ZipCode>zx</ZipCode>
                    <ZipPlus4>zx</ZipPlus4>
                </ChangeOfAddressRcd>
            </Detail>
        </ChangeOfAddress>
    </ChangeOfAddresses>
    <OFAC>
        <Summary>
            <VerificationResult code="1 "/>
            <Counts>
                <OFACReturnCount>zx</OFACReturnCount>
            </Counts>
        </Summary>
    </OFAC>
    <PreviousAddresses>
        <PreviousAddress>
            <Summary>
                <Counts>
                    <PreviousAddressReturnCount>zx</PreviousAddressReturnCount>
                </Counts>
            </Summary>
            <Detail>
                <PreviousAddressRcd>
                    <Address>zx xz xz</Address>
                    <City>zx</City>
                    <State>zx</State>
                    <ZipCode>zx</ZipCode>
                    <ZipPlus4>zx</ZipPlus4>
                    <ReportedDate>zx</ReportedDate>
                    <LastUpdatedDate>zx</LastUpdatedDate>
                </PreviousAddressRcd>
                <PreviousAddressRcd>
                    <Address>zx 2 zx zx</Address>
                    <City>zx</City>
                    <State>zx</State>
                    <ZipCode>zx</ZipCode>
                    <ReportedDate>zx</ReportedDate>
                    <LastUpdatedDate>zx</LastUpdatedDate>
                </PreviousAddressRcd>
            </Detail>
        </PreviousAddress>
    </PreviousAddresses>
    <SSNFinder>
        <Summary>
            <Counts>
                <SSNFinderReturnCount>zx</SSNFinderReturnCount>
            </Counts>
        </Summary>
    </SSNFinder>
</PreciseMatch>

, и это пример xslt, который я написал

<?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output indent="yes"/> 
<xsl:strip-space elements="*"/>

<!--   <xsl:param name="refn" select="11"/> -->
<xsl:template match="/">
    <dataroot>
        <xsl:apply-templates select="@*|node()"/>
    </dataroot>
</xsl:template>

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<!-- Adding ReferenceNumber tag to ChangeOfAddressRcd -->
<xsl:template match="ChangeOfAddressRcd"> 
     <ChangeOfAddressRcd>
        <ReferenceNumber>
            <xsl:value-of select="../../../../../Header/ReferenceNumber"/>
        </ReferenceNumber>
        <xsl:apply-templates select="@*|node()"/>
    </ChangeOfAddressRcd>                      
</xsl:template>

<!-- Adding ReferenceNumber tag to ConsumerIDRcd -->
<xsl:template match="ConsumerIDRcd"> 
    <ConsumerIDRcd>
        <ReferenceNumber>
            <xsl:value-of select="../../../../../Header/ReferenceNumber"/>
        </ReferenceNumber>
        <xsl:apply-templates select="@*|node()"/>
    </ConsumerIDRcd>                      
</xsl:template> 
</xsl:stylesheet>

Он работает и вставляет ссылочный номер для узла <ChangeOfAddressRcd>, но вставляетпустой ссылочный номер для <ConsumerIDRcd> узла.Это та же самая логика и все, но это не вставит сюда по некоторым причинам.Любая помощь приветствуется.Занимался этим более недели, гуглил везде, но не особо повезло.Спасибо

1 Ответ

0 голосов
/ 03 октября 2018

Возможно, будет проще положиться на ancestor вместо того, чтобы пытаться получить правильный родительский уровень, таким образом, вы также можете объединить

<!-- Adding ReferenceNumber tag to ChangeOfAddressRcd -->
<xsl:template match="ChangeOfAddressRcd"> 
     <ChangeOfAddressRcd>
        <ReferenceNumber>
            <xsl:value-of select="../../../../../Header/ReferenceNumber"/>
        </ReferenceNumber>
        <xsl:apply-templates select="@*|node()"/>
    </ChangeOfAddressRcd>                      
</xsl:template>

<!-- Adding ReferenceNumber tag to ConsumerIDRcd -->
<xsl:template match="ConsumerIDRcd"> 
    <ConsumerIDRcd>
        <ReferenceNumber>
            <xsl:value-of select="../../../../../Header/ReferenceNumber"/>
        </ReferenceNumber>
        <xsl:apply-templates select="@*|node()"/>
    </ConsumerIDRcd>                      
</xsl:template> 

с

<xsl:template match="ChangeOfAddressRcd | ConsumerIDRcd">
  <xsl:copy>
    <xsl:apply-templates select="@* | ancestor::PreciseIDServer/Header/ReferenceNumber | node()"/>
  </xsl:copy>
</xsl:template>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...