Настройте xslt для вывода только Specifi c узлов и элементов - PullRequest
0 голосов
/ 07 апреля 2020

Этот xslt выполняет работу по созданию пары имя-значение любого xml фида на него. Мне нужна помощь, чтобы настроить XSLT в соответствии с бизнес-требованиями.

Требование:

  1. Возможность применить преобразование пары имя-значение только к указанным c узлам.

<xsl:function name="func:fqname">
    <xsl:param name="elements" as="element()*"/>
    <xsl:variable name="names" as="xs:string*">
        <xsl:for-each select="$elements">
            <xsl:sequence select="local-name(.)"/>
        </xsl:for-each>
    </xsl:variable>
    <xsl:value-of select="string-join($names, '.')"/>
</xsl:function>

<xsl:template match="/">
    <group>
        <xsl:for-each select="//*[text() and not(descendant::*)]">
            <Name><xsl:value-of select="func:fqname(ancestor-or-self::*)"/></Name>
            <Value><xsl:value-of select="."/></Value>
        </xsl:for-each>
    </group>
</xsl:template>
</xsl:stylesheet>

Пример входящего XML

<SalesQuoteCollection>
<SalesQuote>
    <CurrencyCode>GBP</CurrencyCode>
    <TaxAmount>0.000000</TaxAmount>
    <PriceDateTime>2020-03-17T14:52:55.439</PriceDateTime>
    <DocumentLanguageCode>EN</DocumentLanguageCode>
    <SalesQuoteParty>
        <SalesQuoteParty>
            <PartyName>Porter LLC</PartyName>
            <PartyID>1001</PartyID>
            <RoleCode>1001</RoleCode>
            <RoleCodeText>Account</RoleCodeText>
            <FirstLineName>Porter LLC</FirstLineName>
        </SalesQuoteParty>
        <SalesQuoteParty>
            <PartyName>Manish Admin</PartyName>
            <PartyID>8000000705</PartyID>
            <RoleCode>39</RoleCode>
            <RoleCodeText>Owner</RoleCodeText>
            <FirstLineName>Mr. Manish Admin</FirstLineName>
        </SalesQuoteParty>
        <SalesQuoteParty>
            <PartyName>Manish Admin</PartyName>
            <PartyID>8000000705</PartyID>
            <RoleCode>40</RoleCode>
            <RoleCodeText>Owner</RoleCodeText>
            <FirstLineName>Mr. Manish Admin</FirstLineName>
        </SalesQuoteParty>
    </SalesQuoteParty>
    <ProcessingTypeCode>AG</ProcessingTypeCode>
</SalesQuote>

Требование: 1. SalesQuoteParty требуется только в выходных данных для кода роли = 40 или 39.

Объединить идентификатор кода роли с названием каждого элемента партии.
...