简体   繁体   中英

xslt how to get not keyed nodes?

Input xml:

    <Produkt><Index>275938</Index><Nazwa><RĘKAWICE BRAMKARSKIE PUMA 040959 01 SIZE.11></Nazwa><Ean>887119275938</Ean></Produkt>
    <Produkt><Index>275921</Index><Nazwa><RĘKAWICE BRAMKARSKIE PUMA 040959 01 SIZE.10></Nazwa><Ean>887119275921</Ean></Produkt>
    <Produkt><Index>1001128</Index><Nazwa><ZESTAW DO NURKOWANIA VIZARI JUNIOR XS 32-34></Nazwa><Ean>5902431001128</Ean></Produkt>
    <Produkt><Index>1001111</Index><Nazwa><ZESTAW DO NURKOWANIA VIZARI JUNIOR XXS 30-32></Nazwa><Ean>5902431001111</Ean></Produkt>
    <Produkt><Index>7194A</Index><Nazwa><PUCHAR PLASTIKOWY SREBRNO - NIEBIESKI 7194A></Nazwa><Ean>2010000242261</Ean></Produkt>
    <Produkt><Index>7194B</Index><Nazwa><PUCHAR PLASTIKOWY SREBRNO - NIEBIESKI 7194B></Nazwa><Ean>2010000242278</Ean></Produkt>

Keys:

    <xsl:key name="ProductSize" match="Produkt" use="substring-before(Nazwa, 'SIZE.')" />
    <xsl:key name="ProductSize2" match="Produkt" use="substring-before(translate(Nazwa, '0123456789#', '##########'), '##-##')" />
    <xsl:key name="Restofproducts" match="Produkt" use="???????" />

Hello i'm grouping products based on sizes hidden in name of products, and i need key to store all products which are not in any of other keys.

Expected grouping:

<xsl:key name="ProductSize" match="Produkt" use="substring-before(Nazwa, 'SIZE.')" />
- <Produkt><Nazwa>RĘKAWICE BRAMKARSKIE PUMA 040959 01 SIZE.11</Nazwa></Produkt>
- <Produkt><Nazwa>RĘKAWICE BRAMKARSKIE PUMA 040959 01 SIZE.10</Nazwa></Produkt>
<xsl:key name="ProductSize2" match="Produkt" use="substring-before(translate(Nazwa, '0123456789#', '##########'), '##-##')" />
- <Produkt><Nazwa>ZESTAW DO NURKOWANIA VIZARI JUNIOR XS 32-34</Nazwa></Produkt>
- <Produkt><Nazwa>ZESTAW DO NURKOWANIA VIZARI JUNIOR XXS 30-32</Nazwa></Produkt>
<xsl:key name="Restofproducts" match="Produkt" use="???????" />
- <Produkt><Nazwa>PUCHAR PLASTIKOWY SREBRNO - NIEBIESKI 7194A</Nazwa></Produkt>
- <Produkt><Nazwa>PUCHAR PLASTIKOWY SREBRNO - NIEBIESKI 7194B</Nazwa></Produkt>

Any ideas how "Restofproducts" should looks like?

I'm not quite sure what you mean. Given the definition

<xsl:key name="ProductSize" 
         match="Produkt" 
         use="substring-before(concat(Nazwa, 'SIZE.'), 'SIZE.')" />

this key includes all the Produkt nodes. So when you say "to store all products which are not in any of other keys", there are no such products.

If you want each key to index only a subset of the Produkt elements, you need to define that subset in the match pattern, for example

<xsl:key name="ProductSize" 
         match="Produkt[contains(Nazwa, 'SIZE.')]" 
         use="substring-before(Nazwa, 'SIZE.')" />

You can then match the otherwise-unmatched elements using a complementary predicate, for example match="Produkt[not([contains(Nazwa, 'SIZE.')) and not(...)]"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM