我想使用XSLT在以下XML中包含一些元素,但我无法按预期工作:
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2017-04-10T18:28:30">
<qryXMLOrders>
<IteNumGDS7>1</IteNumGDS7>
<GooDesGDS23>Data</GooDesGDS23>
<GroMasGDS46>0.046</GroMasGDS46>
<NetMasGDS48>0.01</NetMasGDS48>
<ProReqGDI1>10</ProReqGDI1>
<PreProGDI1>00</PreProGDI1>
<ComNatProGIM1>000</ComNatProGIM1>
<StaValAmoGDI1>13.87</StaValAmoGDI1>
<PreDocTypAR21>380</PreDocTypAR21>
<PreDocRefAR26>6471</PreDocRefAR26>
<PreDocCatPREADMREF21>Z</PreDocCatPREADMREF21>
<DocTypDC21>N380</DocTypDC21>
<DocRefDC23>6471</DocRefDC23>
<DocTypDC21A>Y900</DocTypDC21A>
<DocRefDC23A>-</DocRefDC23A>
<DocTypDC21B>Y922</DocTypDC21B>
<DocRefDC23B>-</DocRefDC23B>
<ComNomCMD1>71171900</ComNomCMD1>
<TARCodCMD1>00</TARCodCMD1>
<TARFirAddCodCMD1>0000</TARFirAddCodCMD1>
<TARSecAddCodCMD1>0000</TARSecAddCodCMD1>
<NAtAddCodCMD1>0000</NAtAddCodCMD1>
<NamCE27>Ruthh</NamCE27>
<StrAndNumCE222>9738 SW 94 Terr</StrAndNumCE222>
<PosCodCE223>33176</PosCodCE223>
<CitCE224>Miami</CitCE224>
<CouCE225>US</CouCE225>
<NADLNGGICE>EN</NADLNGGICE>
<MarNumOfPacGS21>RE11628425179GR</MarNumOfPacGS21>
<KinOfPacGS23>EN</KinOfPacGS23>
<NumOfPacGS24>1</NumOfPacGS24>
<InvoiceDate>2017-04-07T00:00:00</InvoiceDate>
<Order_x0020_ID>1184077028</Order_x0020_ID>
</qryXMLOrders>
</dataroot>
所以最终的XML看起来像这样:
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2017-04-10T18:28:30">
<qryXMLOrders>
<IteNumGDS7>1</IteNumGDS7>
<GooDesGDS23>Data</GooDesGDS23>
<GroMasGDS46>0.046</GroMasGDS46>
<NetMasGDS48>0.01</NetMasGDS48>
<ProReqGDI1>10</ProReqGDI1>
<PreProGDI1>00</PreProGDI1>
<ComNatProGIM1>000</ComNatProGIM1>
<StaValAmoGDI1>13.87</StaValAmoGDI1>
<PREADMREFAR2>
<PreDocTypAR21>380</PreDocTypAR21>
<PreDocRefAR26>6471</PreDocRefAR26>
<PreDocCatPREADMREF21>Z</PreDocCatPREADMREF21>
</PREADMREFAR2>
<DocTypDC21>N380</DocTypDC21>
<DocRefDC23>6471</DocRefDC23>
<DocTypDC21A>Y900</DocTypDC21A>
<DocRefDC23A>-</DocRefDC23A>
<DocTypDC21B>Y922</DocTypDC21B>
<DocRefDC23B>-</DocRefDC23B>
<COMCODGODITM>
<ComNomCMD1>71171900</ComNomCMD1>
<TARCodCMD1>00</TARCodCMD1>
<TARFirAddCodCMD1>0000</TARFirAddCodCMD1>
<TARSecAddCodCMD1>0000</TARSecAddCodCMD1>
<NAtAddCodCMD1>0000</NAtAddCodCMD1>
</COMCODGODITM>
<TRACONCE2>
<NamCE27>Ruthh</NamCE27>
<StrAndNumCE222>9738 SW 94 Terr</StrAndNumCE222>
<PosCodCE223>33176</PosCodCE223>
<CitCE224>Miami</CitCE224>
<CouCE225>US</CouCE225>
<NADLNGGICE>EN</NADLNGGICE>
</TRACONCE2>
<PACGS2>
<MarNumOfPacGS21>RE11628425179GR</MarNumOfPacGS21>
<KinOfPacGS23>EN</KinOfPacGS23>
<NumOfPacGS24>1</NumOfPacGS24>
</PACGS2>
<InvoiceDate>2017-04-07T00:00:00</InvoiceDate>
<Order_x0020_ID>1184077028</Order_x0020_ID>
</qryXMLOrders>
</dataroot>
我使用以下XSLT,但是我在XML中出现两次元素,一次解包然后按预期包装:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" />
<xsl:strip-space elements="*"/>
<!-- identity rule Copy all elements and attributes from the source to the target-->
<xsl:template match="@*|node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- Wrap Element -->
<xsl:template match="/dataroot/qryXMLOrders">
<xsl:copy>
<xsl:apply-templates select="PreDocTypAR21|ComNomCMD1|NamCE27|MarNumOfPacGS21/preceding-sibling::*"/>
<PREADMREFAR2>
<xsl:apply-templates select="PreDocTypAR21|PreDocRefAR26|PreDocCatPREADMREF21"/>
</PREADMREFAR2>
<COMCODGODITM>
<xsl:apply-templates select="ComNomCMD1|TARCodCMD1|TARFirAddCodCMD1|TARSecAddCodCMD1|NAtAddCodCMD1"/>
</COMCODGODITM>
<TRACONCE2>
<xsl:apply-templates select="NamCE27|StrAndNumCE222|PosCodCE223|CitCE224|CouCE225|NADLNGGICE"/>
</TRACONCE2>
<PACGS2>
<xsl:apply-templates select="MarNumOfPacGS21|KinOfPacGS23|NumOfPacGS24"/>
</PACGS2>
<xsl:apply-templates select="PreDocCatPREADMREF21|NAtAddCodCMD1|NADLNGGICE|NumOfPacGS24/following-sibling::*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:1)
def primetest(number,primelst):
i=0
limit = int(round(sqrt(number),0)+1)
while primelst[i] < limit:
if (number % primelst[i]) == 0:
return False
i=i+1
return True
上的apply-templates
,其中包含您的基本节点,MarNumOfPacGS21/preceding-sibling::*
的结尾处相同。
默认模板是复制节点,因此如果您不想在更改XSL逻辑时花费时间,只需制作模板而不是跳过不需要的节点:
xsl:copy
未经测试,但你应该明白这一点。