Xml分组辅助查询 [英] Xml grouping secondary query

查看:55
本文介绍了Xml分组辅助查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XML是:

XML is:

<order display="2204">
  <productgroup display="Kitchen Units" lookup="1">
    <supplier display="Chippendale" lookup="90">
      <product display="Base End Support Panel  Natural Oak" what="1" pos="1" ordercat="D" />
      <product display="600MM Highline Integrated Dishwasher Fascia" what="1" pos="2" ordercat="B" />
      <product display="600MM Highline Base Unit" what="1" pos="3" ordercat="D" />
      <product display="600MM Highline Integrated Fridge/Freeezer Fascia" what="1" pos="4" ordercat="D" />
      <product display="600MM 3 Drawer Pan Unit" what="1" pos="5" ordercat="D" />
      <product display="600MM Highline Base Unit" what="1" pos="6" ordercat="D" />
      <product display="500MM Highline Base Unit" what="1" pos="7" ordercat="D" />
      <product display="600MM Fridge/Freezer Housing Unit - Type 6" what="1" pos="8" ordercat="D" />
      <product display="600MM Double Oven Housing Unit - Type 2" what="1" pos="9" ordercat="D" />
      <product display="2650 Plinth Natural Oak Inc Seal Strip" what="1" pos="10" ordercat="D" />
      <product display="Worktop 600 Single P/F 4000 Black Brazil" what="1" pos="11" ordercat="D" />
      <product display="30MM Bullnose Sq Cornice 3600MM Natural" what="1" pos="12" ordercat="D" />
      <product display="10Mtr Roll Edging Tape Natural Oak" what="1" pos="13" ordercat="D" />
      <product display="Schock Stnd Inset 1.5 Bowl  Drainer Sink" what="1" pos="14" ordercat="D" />
      <product display="Schock Universal Plumbing Kit 1.5 Bowl" what="1" pos="15" ordercat="A" />
    </supplier>
  </productgroup>
  <productgroup display="Appliances" lookup="3">
    <supplier display="N/A*******N/A" lookup="130">
      <product display="CDA - Integrated Combination Fridge/freezer 70/30 A+ Rated" what="3" pos="1" ordercat="D" />
      <product display="CDA - Integrated Washing Machine" what="3" pos="2" ordercat="A" />
      <product display="CDA - Double Oven Bi Aa Rated Main Oven Touch Control Clock S/steel" what="3" pos="3" ordercat="D" />
      <product display="CDA - Five Burner Front Control 70cm Gas Hob Wok Ffd Stainless Steel" what="3" pos="4" ordercat="D" />
      <product display="CDA - 70cm Chimney Extractor Hood - Stainless Steel" what="3" pos="5" ordercat="B" />
      <product display="CDA - Fully Integrated Dishwasher 60 Cm A++Aa Rated" what="3" pos="6" ordercat="D" />
    </supplier>
  </productgroup>
</order>





XSL是



XSL is

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output encoding="iso-8859-1"/>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <!-- group -->
    <xsl:key name="level0" match="//product" use="@ordercat"/> 
    	
    <xsl:template match="/">
        <data>
            <xsl:attribute name="type">K8 order creation control file</xsl:attribute>
            <process><xsl:value-of select="count(/order/productgroup/supplier/product[count(. | key('level0', @ordercat)[1]) = 1])"/></process>
            <xsl:for-each select="/order/productgroup/supplier/product[count(. | key('level0', @ordercat)[1]) = 1]">
 
                <order>
                <xsl:attribute name="number"><xsl:number format="1" value="position()"/></xsl:attribute>
				
                <xsl:variable name="onrOrdCat" select="@ordercat" />
                <orderCategory><xsl:value-of select="$onrOrdCat"/></orderCategory>
 
                    <orderLines>
                    <xsl:apply-templates select="../product[@ordercat = $onrOrdCat]" />
                    </orderLines>
                </order>
            </xsl:for-each>
        </data>
    </xsl:template>
	
    <xsl:template match="product">
        <line>
        <xsl:attribute name="what"><xsl:value-of select="@what" /></xsl:attribute>
        <xsl:attribute name="pos"><xsl:value-of select="@pos" /></xsl:attribute>
        </line>
    </xsl:template>
</xsl:stylesheet>





Anticipated output



Anticipated output

<data type="K8 order creation control file">
<process>3</process>
<order number="1">
<orderCategory>D</orderCategory>
<orderLines>
<line what="1" pos="1" />
<line what="1" pos="3" />
<line what="1" pos="4" />
<line what="1" pos="5" />
<line what="1" pos="6" />
<line what="1" pos="7" />
<line what="1" pos="8" />
<line what="1" pos="9" />
<line what="1" pos="10" />
<line what="1" pos="11" />
<line what="1" pos="12" />
<line what="1" pos="13" />
<line what="1" pos="14" />
<line what="3" pos="1" />
<line what="3" pos="3" />
<line what="3" pos="4" />
<line what="3" pos="6" />
</orderLines>
</order>
<order number="2">
<orderCategory>B</orderCategory>
<orderLines>
<line what="1" pos="2" />
<line what="3" pos="5" />
</orderLines>
</order>
<order number="3">
<orderCategory>A</orderCategory>
<orderLines>
<line what="1" pos="15" />
<line what="3" pos="2" />
</orderLines>
</order>
</data>





What I have tried:



George Jonsson brilliantly gave me the XSL, however after further testing the grouping needs to be refined a little and needs to look at multiple levels and iterate through them. There could be multiple or single ordercat, multiple or single supplier, multiple or single product group and mixtures thereof. Any help really appreciated.



What I have tried:

George Jonsson brilliantly gave me the XSL, however after further testing the grouping needs to be refined a little and needs to look at multiple levels and iterate through them. There could be multiple or single ordercat, multiple or single supplier, multiple or single product group and mixtures thereof. Any help really appreciated.

推荐答案

onrOrdCat\"/></orderCategory>

<orderLines>
<xsl:apply-templates select=\"../product[@ordercat =
onrOrdCat"/></orderCategory> <orderLines> <xsl:apply-templates select="../product[@ordercat =


onrOrdCat]\" />
</orderLines>
</order>
</xsl:for-each>
</data>
</xsl:template>
\t
<xsl:template match=\"product\">
<line>
<xsl:attribute name=\"what\"><xsl:value-of select=\"@what\" /></xsl:attribute>
<xsl:attribute name=\"pos\"><xsl:value-of select=\"@pos\" /></xsl:attribute>
</line>
</xsl:template>
</xsl:stylesheet>
onrOrdCat]" /> </orderLines> </order> </xsl:for-each> </data> </xsl:template> <xsl:template match="product"> <line> <xsl:attribute name="what"><xsl:value-of select="@what" /></xsl:attribute> <xsl:attribute name="pos"><xsl:value-of select="@pos" /></xsl:attribute> </line> </xsl:template> </xsl:stylesheet>





Anticipated output



Anticipated output

<data type="K8 order creation control file">
<process>3</process>
<order number="1">
<orderCategory>D</orderCategory>
<orderLines>
<line what="1" pos="1" />
<line what="1" pos="3" />
<line what="1" pos="4" />
<line what="1" pos="5" />
<line what="1" pos="6" />
<line what="1" pos="7" />
<line what="1" pos="8" />
<line what="1" pos="9" />
<line what="1" pos="10" />
<line what="1" pos="11" />
<line what="1" pos="12" />
<line what="1" pos="13" />
<line what="1" pos="14" />
<line what="3" pos="1" />
<line what="3" pos="3" />
<line what="3" pos="4" />
<line what="3" pos="6" />
</orderLines>
</order>
<order number="2">
<orderCategory>B</orderCategory>
<orderLines>
<line what="1" pos="2" />
<line what="3" pos="5" />
</orderLines>
</order>
<order number="3">
<orderCategory>A</orderCategory>
<orderLines>
<line what="1" pos="15" />
<line what="3" pos="2" />
</orderLines>
</order>
</data>





What I have tried:



George Jonsson brilliantly gave me the XSL, however after further testing the grouping needs to be refined a little and needs to look at multiple levels and iterate through them. There could be multiple or single ordercat, multiple or single supplier, multiple or single product group and mixtures thereof. Any help really appreciated.



What I have tried:

George Jonsson brilliantly gave me the XSL, however after further testing the grouping needs to be refined a little and needs to look at multiple levels and iterate through them. There could be multiple or single ordercat, multiple or single supplier, multiple or single product group and mixtures thereof. Any help really appreciated.


The problem was that you need to walk up the tree and select productgroup, then go down the tree again to find all lines.



Modified XSD

The problem was that you need to walk up the tree and select productgroup, then go down the tree again to find all lines.

Modified XSD
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output encoding="iso-8859-1" />
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    <!-- group -->
    <xsl:key name="level0" match="//product" use="@ordercat" /> 
    	
    <xsl:template match="/">
        <data>
            <xsl:attribute name="type">K8 order creation control file</xsl:attribute>
            <process><xsl:value-of select="count(/order/productgroup/supplier/product[count(. | key('level0', @ordercat)[1]) = 1])" /></process>
            <xsl:for-each select="/order/productgroup/supplier/product[count(. | key('level0', @ordercat)[1]) = 1]">
 
                <order>
					<xsl:attribute name="number"><xsl:number format="1" value="position()" /></xsl:attribute>
				
					<xsl:variable name="onrOrdCat" select="@ordercat" />
					<ordercategory><xsl:value-of select="


这篇关于Xml分组辅助查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆