我花了很多时间试图让下面的xml的muenchian分组工作,但我无法让它工作。我尝试了许多不同的方法,所以发布最近的尝试可能只会让任何想要帮助我的人感到困惑。 : - )
Xslt需要为1.0
输入文件是发票行,其中“发票标题信息”与属于特定发票的每一行重复。
分组应在字段_id中进行,即在RESULTSET / ROW“/ COL [12] / DATA中的值(例如'C82F1B47-9758-4D18-ABD7-80386385F6AD')
COL [21]到COL [27]是发票的不同发票行,因此应逐行列出并列在相应的发票下。
输入xml(来自Filemaker):
<?xml version="1.0" encoding="UTF-8" ?>
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<ERRORCODE>0</ERRORCODE>
<PRODUCT BUILD="01-22-2016" NAME="FileMaker" VERSION="ProAdvanced 14.0.5"/>
<DATABASE DATEFORMAT="Yyyy-m-d" LAYOUT="" NAME="fmStaben.fmp12" RECORDS="113" TIMEFORMAT="k:mm:ss "/>
<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_MEMBER" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_MEDLEM_KSIFFER" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_FIRST_NAME" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_LAST_NAME" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_FIRST_PNAME" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_LAST_PNAME" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_ADDRESS1" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_ADDRESS2" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_ZIP" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_CITY" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_STATE" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::_id" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_ORDERNR" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_POSTAGE" TYPE="NUMBER"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_ORDER_TOTAL" TYPE="NUMBER"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_DISCOUNT" TYPE="NUMBER"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_MVA_AMOUNT" TYPE="NUMBER"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_AMOUNT_TO_PAY" TYPE="NUMBER"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_KID" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OrderHeader::OH_AMOUNT_MODUS" TYPE="NUMBER"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OL_LINE" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OL_LTYPE" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OL_ART_NR" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OL_ART_TEXT" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OL_QUANTITY" TYPE="NUMBER"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OL_PRICE" TYPE="NUMBER"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="OL_TOTAL" TYPE="NUMBER"/>
</METADATA>
<RESULTSET FOUND="6">
<ROW MODID="0" RECORDID="601">
<COL>
<DATA>109948</DATA>
</COL>
<COL>
<DATA>45</DATA>
</COL>
<COL>
<DATA>JOHN</DATA>
</COL>
<COL>
<DATA>DOE</DATA>
</COL>
<COL>
<DATA>JAMES</DATA>
</COL>
<COL>
<DATA>DOE</DATA>
</COL>
<COL>
<DATA>2323 MAIN STREET</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>999 99</DATA>
</COL>
<COL>
<DATA>MAGIC KINGDOM</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>C82F1B47-9758-4D18-ABD7-80386385F6AD</DATA>
</COL>
<COL>
<DATA>409949</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA>3534534534517</DATA>
</COL>
<COL>
<DATA>7</DATA>
</COL>
<COL>
<DATA>010</DATA>
</COL>
<COL>
<DATA>A</DATA>
</COL>
<COL>
<DATA>99-131015DM</DATA>
</COL>
<COL>
<DATA>WORLD CUP KIT 1</DATA>
</COL>
<COL>
<DATA>1</DATA>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
</ROW>
<ROW MODID="0" RECORDID="602">
<COL>
<DATA>109948</DATA>
</COL>
<COL>
<DATA>45</DATA>
</COL>
<COL>
<DATA>JOHN</DATA>
</COL>
<COL>
<DATA>DOE</DATA>
</COL>
<COL>
<DATA>JAMES</DATA>
</COL>
<COL>
<DATA>DOE</DATA>
</COL>
<COL>
<DATA>2323 MAIN STREET</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>999 99</DATA>
</COL>
<COL>
<DATA>MAGIC KINGDOM</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>C82F1B47-9758-4D18-ABD7-80386385F6AD</DATA>
</COL>
<COL>
<DATA>409949</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA>3534534534517</DATA>
</COL>
<COL>
<DATA>7</DATA>
</COL>
<COL>
<DATA>020</DATA>
</COL>
<COL>
<DATA>A</DATA>
</COL>
<COL>
<DATA>99-140312DM</DATA>
</COL>
<COL>
<DATA>WORLD CUP KIT 2</DATA>
</COL>
<COL>
<DATA>1</DATA>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
</ROW>
<ROW MODID="0" RECORDID="603">
<COL>
<DATA>049985</DATA>
</COL>
<COL>
<DATA>77</DATA>
</COL>
<COL>
<DATA>TEST</DATA>
</COL>
<COL>
<DATA>VON TEST</DATA>
</COL>
<COL>
<DATA>TESTPARENT</DATA>
</COL>
<COL>
<DATA>VON TEST</DATA>
</COL>
<COL>
<DATA>789 LEFT STREET</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>999 99</DATA>
</COL>
<COL>
<DATA>MAGIC KINGDOM</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>5A2D83C6-ECEB-4636-968E-97DC6E5B1C8A</DATA>
</COL>
<COL>
<DATA>409950</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA>92350429953250</DATA>
</COL>
<COL>
<DATA>7</DATA>
</COL>
<COL>
<DATA>010</DATA>
</COL>
<COL>
<DATA>A</DATA>
</COL>
<COL>
<DATA>99-140312DM</DATA>
</COL>
<COL>
<DATA>WORLD CUP KIT 3</DATA>
</COL>
<COL>
<DATA>1</DATA>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
</ROW>
<ROW MODID="0" RECORDID="605">
<COL>
<DATA>129984</DATA>
</COL>
<COL>
<DATA>15</DATA>
</COL>
<COL>
<DATA>CARL</DATA>
</COL>
<COL>
<DATA>DOE</DATA>
</COL>
<COL>
<DATA>JANE</DATA>
</COL>
<COL>
<DATA>DOE</DATA>
</COL>
<COL>
<DATA>4525 GREAT ROAD</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>999 99</DATA>
</COL>
<COL>
<DATA>MAGIC KINGDOM</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>478E8CF0-7C93-4BE4-B314-FBCBDB5184F0</DATA>
</COL>
<COL>
<DATA>409951</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA>92359999843251</DATA>
</COL>
<COL>
<DATA>7</DATA>
</COL>
<COL>
<DATA>020</DATA>
</COL>
<COL>
<DATA>A</DATA>
</COL>
<COL>
<DATA>99-1407156</DATA>
</COL>
<COL>
<DATA>150 FOOTBALL LEGENDS</DATA>
</COL>
<COL>
<DATA>1</DATA>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
</ROW>
<ROW MODID="0" RECORDID="606">
<COL>
<DATA>129984</DATA>
</COL>
<COL>
<DATA>15</DATA>
</COL>
<COL>
<DATA>CARL</DATA>
</COL>
<COL>
<DATA>DOE</DATA>
</COL>
<COL>
<DATA>JANE</DATA>
</COL>
<COL>
<DATA>DOE</DATA>
</COL>
<COL>
<DATA>4525 GREAT ROAD</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>999 99</DATA>
</COL>
<COL>
<DATA>MAGIC KINGDOM</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>478E8CF0-7C93-4BE4-B314-FBCBDB5184F0</DATA>
</COL>
<COL>
<DATA>409951</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA>92359999843251</DATA>
</COL>
<COL>
<DATA>7</DATA>
</COL>
<COL>
<DATA>030</DATA>
</COL>
<COL>
<DATA>A</DATA>
</COL>
<COL>
<DATA>99-140312DM</DATA>
</COL>
<COL>
<DATA>WORLD CUP KIT 3</DATA>
</COL>
<COL>
<DATA>1</DATA>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
</ROW>
<ROW MODID="0" RECORDID="607">
<COL>
<DATA>129984</DATA>
</COL>
<COL>
<DATA>15</DATA>
</COL>
<COL>
<DATA>CARL</DATA>
</COL>
<COL>
<DATA>DOE</DATA>
</COL>
<COL>
<DATA>JANE</DATA>
</COL>
<COL>
<DATA>DOE</DATA>
</COL>
<COL>
<DATA>4525 GREAT ROAD</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>999 99</DATA>
</COL>
<COL>
<DATA>MAGIC KINGDOM</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>478E8CF0-7C93-4BE4-B314-FBCBDB5184F0</DATA>
</COL>
<COL>
<DATA>409951</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
<COL>
<DATA>49,00</DATA>
</COL>
<COL>
<DATA>92359999843251</DATA>
</COL>
<COL>
<DATA>7</DATA>
</COL>
<COL>
<DATA>040</DATA>
</COL>
<COL>
<DATA>A</DATA>
</COL>
<COL>
<DATA>99-1402175</DATA>
</COL>
<COL>
<DATA>WORLD CUP KIT 2</DATA>
</COL>
<COL>
<DATA>1</DATA>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
<COL>
<DATA>0,00</DATA>
</COL>
</ROW>
</RESULTSET>
</FMPXMLRESULT>
需要输出xml:
<?xml version="1.0" encoding="UTF-8" ?>
<Invoices>
<Invoice>
<Recipient>
<MemberNo>109948</MemberNo>
<CheckDigit>99</CheckDigit>
<FirstName>JOHN</FirstName>
<LastName>DOE</LastName>
<GuardianFirstName>JAMES</GuardianFirstName>
<GuardianLastName>DOE</GuardianLastName>
<Address1>2323 MAIN STREET</Address1>
<Address2/>
<PostalCode>999 99</PostalCode>
<City>MAGIC KINGDOM</City>
<State/>
</Recipient>
<InvoiceHeader>
<OrderNo>409949</OrderNo>
<Postage>49,00</Postage>
<OrderTotal>49,00</OrderTotal>
<Discount/>
<VATAmount>0,00</VATAmount>
<AmountToPay>49,00</AmountToPay>
<PaymentReferenceNo>3534534534517</PaymentReferenceNo>
<AmountModus>7</AmountModus>
</InvoiceHeader>
<InvoiceLines>
<InvoiceLine>
<LineNo>010</LineNo>
<LineType>A</LineType>
<ItemNo>99-131015DM</ItemNo>
<ItemDescription>WORLD CUP KIT 1</ItemDescription>
<Quantity>1</Quantity>
<UnitPrice>0,00</UnitPrice>
<LineAmount>0,00</LineAmount>
</InvoiceLine>
<InvoiceLine>
<LineNo>020</LineNo>
<LineType>A</LineType>
<ItemNo>99-140312DM</ItemNo>
<ItemDescription>WORLD CUP KIT 2</ItemDescription>
<Quantity>1</Quantity>
<UnitPrice>0,00</UnitPrice>
<LineAmount>0,00</LineAmount>
</InvoiceLine>
</InvoiceLines>
</Invoice>
<Invoice>
<Recipient>
<MemberNo>049985</MemberNo>
<CheckDigit>77</CheckDigit>
<FirstName>TEST</FirstName>
<LastName>VON TEST</LastName>
<GuardianFirstName>TESTPARENT</GuardianFirstName>
<GuardianLastName>VON TEST</GuardianLastName>
<Address1>789 LEFT STREET</Address1>
<Address2/>
<PostalCode>999 99</PostalCode>
<City>MAGIC KINGDOM</City>
<State/>
</Recipient>
<InvoiceHeader>
<OrderNo>409950</OrderNo>
<Postage>49,00</Postage>
<OrderTotal>49,00</OrderTotal>
<Discount/>
<VATAmount>0,00</VATAmount>
<AmountToPay>49,00</AmountToPay>
<PaymentReferenceNo>92350429953250</PaymentReferenceNo>
<AmountModus>7</AmountModus>
</InvoiceHeader>
<InvoiceLines>
<InvoiceLine>
<LineNo>010</LineNo>
<LineType/>
<ItemNo>99-140312DM</ItemNo>
<ItemDescription>WORLD CUP KIT 3</ItemDescription>
<Quantity>1</Quantity>
<UnitPrice>0,00</UnitPrice>
<LineAmount>0,00</LineAmount>
</InvoiceLine>
</InvoiceLines>
</Invoice>
<Invoice>
<Recipient>
<MemberNo>129984</MemberNo>
<CheckDigit>15</CheckDigit>
<FirstName>CARL</FirstName>
<LastName>DOE</LastName>
<GuardianFirstName>JANE</GuardianFirstName>
<GuardianLastName>DOE</GuardianLastName>
<Address1>4525 GREAT ROAD</Address1>
<Address2/>
<PostalCode>999 99</PostalCode>
<City>MAGIC KINGDOM</City>
<State/>
</Recipient>
<InvoiceHeader>
<OrderNo>409951</OrderNo>
<Postage>49,00</Postage>
<OrderTotal>49,00</OrderTotal>
<Discount/>
<VATAmount>0,00</VATAmount>
<AmountToPay>49,00</AmountToPay>
<PaymentReferenceNo>92359999843251</PaymentReferenceNo>
<AmountModus>7</AmountModus>
</InvoiceHeader>
<InvoiceLines>
<InvoiceLine>
<LineNo>020</LineNo>
<LineType>A</LineType>
<ItemNo>99-1407156</ItemNo>
<ItemDescription>150 FOOTBALL LEGENDS</ItemDescription>
<Quantity>1</Quantity>
<UnitPrice>0,00</UnitPrice>
<LineAmount>0,00</LineAmount>
</InvoiceLine>
<InvoiceLine>
<LineNo>030</LineNo>
<LineType>A</LineType>
<ItemNo>99-140312DM</ItemNo>
<ItemDescription>WORLD CUP KIT 3</ItemDescription>
<Quantity>1</Quantity>
<UnitPrice>0,00</UnitPrice>
<LineAmount>0,00</LineAmount>
</InvoiceLine>
<InvoiceLine>
<LineNo>040</LineNo>
<LineType>A</LineType>
<ItemNo>99-1402175</ItemNo>
<ItemDescription>WORLD CUP KIT 2</ItemDescription>
<Quantity>1</Quantity>
<UnitPrice>0,00</UnitPrice>
<LineAmount>0,00</LineAmount>
</InvoiceLine>
</InvoiceLines>
</Invoice>
</Invoices>
我经常使用Xlst作为基础来从输入xml中获取值。我在其他几个场合使用它时,我不需要对数据进行分组(并且输出的格式有点不同):
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fmp="http://www.filemaker.com/fmpxmlresult"
exclude-result-prefixes="fmp"
>
<xsl:output method="xml" indent="yes" />
<xsl:template match="/fmp:FMPXMLRESULT">
<Invoices>
<xsl:apply-templates select="fmp:RESULTSET/fmp:ROW" />
</Invoices>
</xsl:template>
<xsl:template match="fmp:RESULTSET/fmp:ROW">
<Invoice>
<Recipient>
<MemberNo>
<xsl:apply-templates select="fmp:COL[1]" />
</MemberNo>
<CheckDigit>
<xsl:apply-templates select="fmp:COL[2]" />
</CheckDigit>
<FirstName>
<xsl:apply-templates select="fmp:COL[3]" />
</FirstName>
<LastName>
<xsl:apply-templates select="fmp:COL[4]" />
</LastName>
<GuardianFirstName>
<xsl:apply-templates select="fmp:COL[5]" />
</GuardianFirstName>
<GuardianLastName>
<xsl:apply-templates select="fmp:COL[6]" />
</GuardianLastName>
<Address1>
<xsl:apply-templates select="fmp:COL[7]" />
</Address1>
<Address2>
<xsl:apply-templates select="fmp:COL[8]" />
</Address2>
<PostalCode>
<xsl:apply-templates select="fmp:COL[9]" />
</PostalCode>
<City>
<xsl:apply-templates select="fmp:COL[10]" />
</City>
<State>
<xsl:apply-templates select="fmp:COL[11]" />
</State>
</Recipient>
<InvoiceHeader>
<OrderNo>
<xsl:apply-templates select="fmp:COL[12]" />
</OrderNo>
<Postage>
<xsl:apply-templates select="fmp:COL[13]" />
</Postage>
<OrderTotal>
<xsl:apply-templates select="fmp:COL[14]" />
</OrderTotal>
<Discount>
<xsl:apply-templates select="fmp:COL[15]" />
</Discount>
<VATAmount>
<xsl:apply-templates select="fmp:COL[16]" />
</VATAmount>
<AmountToPay>
<xsl:apply-templates select="fmp:COL[17]" />
</AmountToPay>
<PaymentReferenceNo>
<xsl:apply-templates select="fmp:COL[18]" />
</PaymentReferenceNo>
<AmountModus>
<xsl:apply-templates select="fmp:COL[19]" />
</AmountModus>
</InvoiceHeader>
<InvoiceLines>
<InvoiceLine>
<LineNo>
<xsl:apply-templates select="fmp:COL[20]" />
</LineNo>
<LineType>
<xsl:apply-templates select="fmp:COL[21]" />
</LineType>
<ItemNo>
<xsl:apply-templates select="fmp:COL[22]" />
</ItemNo>
<ItemDescription>
<xsl:apply-templates select="fmp:COL[23]" />
</ItemDescription>
<Quantity>
<xsl:apply-templates select="fmp:COL[24]" />
</Quantity>
<UnitPrice>
<xsl:apply-templates select="fmp:COL[25]" />
</UnitPrice>
<LineAmount>
<xsl:apply-templates select="fmp:COL[26]" />
</LineAmount>
</InvoiceLine>
</InvoiceLines>
</Invoice>
</xsl:template>
<!-- the key indexes the METADATA fields by their position -->
<xsl:key
name="kMetaData"
match="fmp:METADATA/fmp:FIELD"
use="count(preceding-sibling::fmp:FIELD) + 1"
/>
<!-- OrderHeader::OH_MEMBER -->
<xsl:template match="fmp:COL[1]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_MEDLEM_KSIFFER -->
<xsl:template match="fmp:COL[2]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_FIRST_NAME -->
<xsl:template match="fmp:COL[3]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_LAST_NAME -->
<xsl:template match="fmp:COL[4]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_FIRST_PNAME -->
<xsl:template match="fmp:COL[5]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_LAST_PNAME -->
<xsl:template match="fmp:COL[6]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_ADDRESS1 -->
<xsl:template match="fmp:COL[7]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_ADDRESS2 -->
<xsl:template match="fmp:COL[8]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_ZIP -->
<xsl:template match="fmp:COL[9]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_CITY -->
<xsl:template match="fmp:COL[10]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_STATE -->
<xsl:template match="fmp:COL[11]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::_id -->
<xsl:template match="fmp:COL[12]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_ORDERNO -->
<xsl:template match="fmp:COL[13]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_POSTAGE -->
<xsl:template match="fmp:COL[14]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_ORDER_TOTAL -->
<xsl:template match="fmp:COL[15]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_DISCOUNT -->
<xsl:template match="fmp:COL[16]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_MVA_AMOUNT -->
<xsl:template match="fmp:COL[17]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_AMOUNT_TO_PAY -->
<xsl:template match="fmp:COL[18]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_KID -->
<xsl:template match="fmp:COL[19]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OrderHeader::OH_AMOUNT_MODUS -->
<xsl:template match="fmp:COL[20]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OL_LINE -->
<xsl:template match="fmp:COL[21]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OL_LTYPE -->
<xsl:template match="fmp:COL[22]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OL_ART_NR -->
<xsl:template match="fmp:COL[23]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OL_ART_TEXT -->
<xsl:template match="fmp:COL[24]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OL_QUANTITY -->
<xsl:template match="fmp:COL[25]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OL_PRICE -->
<xsl:template match="fmp:COL[26]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
<!-- OL_TOTAL -->
<xsl:template match="fmp:COL[27]">
<xsl:value-of select="fmp:DATA" />
</xsl:template>
</xsl:stylesheet>
提前感谢任何想要花时间帮助我的人。 :-) // Freppan
答案 0 :(得分:2)
如果您在从FileMaker导出时进行XSL转换,则不需要使用Muenchian分组。您可以利用FileMaker的XSLT引擎支持的EXSLT set:distinct()
extension function:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fmp="http://www.filemaker.com/fmpxmlresult"
xmlns:set="http://exslt.org/sets"
exclude-result-prefixes="fmp set">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="group" match="fmp:ROW" use="fmp:COL[12]/fmp:DATA" />
<xsl:template match="/fmp:FMPXMLRESULT">
<Invoices>
<xsl:for-each select="set:distinct(fmp:RESULTSET/fmp:ROW/fmp:COL[12]/fmp:DATA)">
<Invoice>
<Recipient>
<MemberNo>
<xsl:value-of select="../../fmp:COL[1]/fmp:DATA" />
</MemberNo>
<CheckDigit>
<xsl:value-of select="../../fmp:COL[2]/fmp:DATA" />
</CheckDigit>
<FirstName>
<xsl:value-of select="../../fmp:COL[3]/fmp:DATA" />
</FirstName>
<LastName>
<xsl:value-of select="../../fmp:COL[4]/fmp:DATA" />
</LastName>
<GuardianFirstName>
<xsl:value-of select="../../fmp:COL[5]/fmp:DATA" />
</GuardianFirstName>
<GuardianLastName>
<xsl:value-of select="../../fmp:COL[6]/fmp:DATA" />
</GuardianLastName>
<Address1>
<xsl:value-of select="../../fmp:COL[7]/fmp:DATA" />
</Address1>
<Address2>
<xsl:value-of select="../../fmp:COL[8]/fmp:DATA" />
</Address2>
<PostalCode>
<xsl:value-of select="../../fmp:COL[9]/fmp:DATA" />
</PostalCode>
<City>
<xsl:value-of select="../../fmp:COL[10]/fmp:DATA" />
</City>
<State>
<xsl:value-of select="../../fmp:COL[11]/fmp:DATA" />
</State>
</Recipient>
<InvoiceHeader>
<OrderNo>
<xsl:value-of select="../../fmp:COL[12]/fmp:DATA" />
</OrderNo>
<Postage>
<xsl:value-of select="../../fmp:COL[13]/fmp:DATA" />
</Postage>
<OrderTotal>
<xsl:value-of select="../../fmp:COL[14]/fmp:DATA" />
</OrderTotal>
<Discount>
<xsl:value-of select="../../fmp:COL[15]/fmp:DATA" />
</Discount>
<VATAmount>
<xsl:value-of select="../../fmp:COL[16]/fmp:DATA" />
</VATAmount>
<AmountToPay>
<xsl:value-of select="../../fmp:COL[17]/fmp:DATA" />
</AmountToPay>
<PaymentReferenceNo>
<xsl:value-of select="../../fmp:COL[18]/fmp:DATA" />
</PaymentReferenceNo>
<AmountModus>
<xsl:value-of select="../../fmp:COL[19]/fmp:DATA" />
</AmountModus>
</InvoiceHeader>
<InvoiceLines>
<xsl:for-each select="key('group', .)" >
<InvoiceLine>
<LineNo>
<xsl:value-of select="fmp:COL[20]/fmp:DATA" />
</LineNo>
<LineType>
<xsl:value-of select="fmp:COL[21]/fmp:DATA" />
</LineType>
<ItemNo>
<xsl:value-of select="fmp:COL[22]/fmp:DATA" />
</ItemNo>
<ItemDescription>
<xsl:value-of select="fmp:COL[23]/fmp:DATA" />
</ItemDescription>
<Quantity>
<xsl:value-of select="fmp:COL[24]/fmp:DATA" />
</Quantity>
<UnitPrice>
<xsl:value-of select="fmp:COL[25]/fmp:DATA" />
</UnitPrice>
<LineAmount>
<xsl:value-of select="fmp:COL[26]/fmp:DATA" />
</LineAmount>
</InvoiceLine>
</xsl:for-each>
</InvoiceLines>
</Invoice>
</xsl:for-each>
</Invoices>
</xsl:template>
</xsl:stylesheet>
答案 1 :(得分:1)
好吧,如果您知道要分组的项目,那么定义密钥<xsl:key name="group" match="fmp:ROW" use="fmp:COL[12]/fmp:DATA"/>
并使用它并不困难:
<xsl:key name="group" match="fmp:ROW" use="fmp:COL[12]/fmp:DATA"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/fmp:FMPXMLRESULT">
<Invoices>
<xsl:apply-templates
select="fmp:RESULTSET/fmp:ROW[generate-id() = generate-id(key('group', fmp:COL[12]/fmp:DATA)[1])]"
/>
</Invoices>
</xsl:template>
<xsl:template match="fmp:RESULTSET/fmp:ROW">
<Invoice>
<Recipient>
<MemberNo>
<xsl:apply-templates select="fmp:COL[1]"/>
</MemberNo>
<CheckDigit>
<xsl:apply-templates select="fmp:COL[2]"/>
</CheckDigit>
<FirstName>
<xsl:apply-templates select="fmp:COL[3]"/>
</FirstName>
<LastName>
<xsl:apply-templates select="fmp:COL[4]"/>
</LastName>
<GuardianFirstName>
<xsl:apply-templates select="fmp:COL[5]"/>
</GuardianFirstName>
<GuardianLastName>
<xsl:apply-templates select="fmp:COL[6]"/>
</GuardianLastName>
<Address1>
<xsl:apply-templates select="fmp:COL[7]"/>
</Address1>
<Address2>
<xsl:apply-templates select="fmp:COL[8]"/>
</Address2>
<PostalCode>
<xsl:apply-templates select="fmp:COL[9]"/>
</PostalCode>
<City>
<xsl:apply-templates select="fmp:COL[10]"/>
</City>
<State>
<xsl:apply-templates select="fmp:COL[11]"/>
</State>
</Recipient>
<InvoiceHeader>
<OrderNo>
<xsl:apply-templates select="fmp:COL[13]"/>
</OrderNo>
<Postage>
<xsl:apply-templates select="fmp:COL[14]"/>
</Postage>
<OrderTotal>
<xsl:apply-templates select="fmp:COL[15]"/>
</OrderTotal>
<Discount>
<xsl:apply-templates select="fmp:COL[16]"/>
</Discount>
<VATAmount>
<xsl:apply-templates select="fmp:COL[17]"/>
</VATAmount>
<AmountToPay>
<xsl:apply-templates select="fmp:COL[18]"/>
</AmountToPay>
<PaymentReferenceNo>
<xsl:apply-templates select="fmp:COL[19]"/>
</PaymentReferenceNo>
<AmountModus>
<xsl:apply-templates select="fmp:COL[20]"/>
</AmountModus>
</InvoiceHeader>
<InvoiceLines>
<xsl:for-each select="key('group', fmp:COL[12]/fmp:DATA)">
<InvoiceLine>
<LineNo>
<xsl:apply-templates select="fmp:COL[21]"/>
</LineNo>
<LineType>
<xsl:apply-templates select="fmp:COL[22]"/>
</LineType>
<ItemNo>
<xsl:apply-templates select="fmp:COL[23]"/>
</ItemNo>
<ItemDescription>
<xsl:apply-templates select="fmp:COL[24]"/>
</ItemDescription>
<Quantity>
<xsl:apply-templates select="fmp:COL[25]"/>
</Quantity>
<UnitPrice>
<xsl:apply-templates select="fmp:COL[26]"/>
</UnitPrice>
<LineAmount>
<xsl:apply-templates select="fmp:COL[27]"/>
</LineAmount>
</InvoiceLine>
</xsl:for-each>
</InvoiceLines>
</Invoice>
</xsl:template>
<xsl:template match="fmp:COL">
<xsl:value-of select="fmp:DATA"/>
</xsl:template>
我重用了你的代码(必须增加一些位置谓词),我会考虑清理所有<xsl:apply-templates select="fmp:COL[N]"/>
以简单地使用<xsl:value-of select="fmp:COL[N]/fmp:DATA"/>
,但是,在这种情况下,将处理推送到模板会没有真正实现一些转变。