我很感激一些输入和帮助解决了我对XML和FOP的问题。
从这个xml:
Sales Qty
如何从一个节点组合阅读 PartDesc ,从另一个节点阅读评论以获得如下内容:
我想这需要使用 GId 0281 GId 和 GuideNumber number =" 0281" type ="未指定" 但我不知道如何。
我现在正在使用这个xsl-fo:
<selectedcalculation>
<CLASSXml>
<CalcData>
<SpareParts>
<PartDtls>
<PartDtl>
<RepTyp>E</RepTyp>
<GId>0281</GId>
<PartDesc>FRONT BUMPER</PartDesc>
<PartNo>16 107 424 80</PartNo>
<Price Cur="HRK">+2496.37</Price>
</PartDtl>
<PartDtl>
<RepTyp>E</RepTyp>
<GId>0471</GId>
<PartDesc>HOOD</PartDesc>
<PartNo>98 021 631 80</PartNo>
<Price Cur="HRK">+2273.92</Price>
</PartDtl>
<PartDtl>
<RepTyp>E</RepTyp>
<GId>0561</GId>
<PartDesc>LEFT HEADLIGHT</PartDesc>
<PartNo>16 180 003 80</PartNo>
<Price Cur="HRK">+4756.61</Price>
</PartDtl>
<PartDtl>
<RepTyp>E</RepTyp>
<GId>0741</GId>
<PartDesc>LEFT FRONT FENDER</PartDesc>
<PartNo>98 021 643 80</PartNo>
<Price Cur="HRK">+1162.04</Price>
</PartDtl>
</PartDtls>
</SpareParts>
</CalcData>
</CLASSXml>
<repairCaptureData>
<Capoeira>
<RepairData>
<RepairPartList>
<ClassicRepairPartBasic>
<GuideNumber number="0471" type="Unspecified"/>
<RepairInfoList>
<ClassicRepairInfoSPVehicle>
<RepairMethod>E</RepairMethod>
<Comment>Installation control</Comment>
</ClassicRepairInfoSPVehicle>
</RepairInfoList>
</ClassicRepairPartBasic>
<ClassicRepairPartBasic>
<GuideNumber number="0281" type="Unspecified"/>
<RepairInfoList>
<ClassicRepairInfoSPVehicle>
<RepairMethod>E</RepairMethod>
</ClassicRepairInfoSPVehicle>
</RepairInfoList>
</ClassicRepairPartBasic>
<ClassicRepairPartBasic>
<GuideNumber number="0561" type="Unspecified"/>
<RepairInfoList>
<ClassicRepairInfoSPVehicle>
<RepairMethod>E</RepairMethod>
</ClassicRepairInfoSPVehicle>
</RepairInfoList>
</ClassicRepairPartBasic>
<ClassicRepairPartBasic>
<GuideNumber number="0741" type="Unspecified"/>
<RepairInfoList>
<ClassicRepairInfoSPVehicle>
<RepairMethod>E</RepairMethod>
<Comment>Return to insurance</Comment>
</ClassicRepairInfoSPVehicle>
</RepairInfoList>
</ClassicRepairPartBasic>
</RepairPartList>
</RepairData>
</Capoeira>
</repairCaptureData>
</selectedcalculation>
提前致谢!
答案 0 :(得分:0)
您应该只在XML树上导航。获取具有GId值的GuideNumber兄弟之前的节点RepairInfoList。使用带有重复谓词的XPath:
<xsl:value-of select="ancestor::selectedcalculation/repairCaptureData/descendant::RepairInfoList[preceding-sibling::GuideNumber[@number = $MyGId]]/ClassicRepairInfoSPVehicle/Comment"/>
答案 1 :(得分:0)
尝试以下方法。 xsl:key
和key()
函数对于在文档的其他部分中进行查找非常有用。 fo:list-block
和相关的FO旨在制作列表。见https://www.w3.org/TR/xsl11/#d0e12374。最后,将事物分解为多个xsl:template
可以让文档的结构决定发生了什么,使XPath更短,并且我发现,使模板更短更容易理解。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
<xsl:strip-space elements="*" />
<xsl:key name="PartDtl" match="PartDtl" use="GId" />
<xsl:template match="selectedcalculation">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="spm">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="spm">
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select="repairCaptureData" />
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="RepairPartList">
<fo:list-block>
<xsl:apply-templates select="ClassicRepairPartBasic">
<xsl:sort select="key('PartDtl', GuideNumber/@number)/PartDesc" />
</xsl:apply-templates>
</fo:list-block>
</xsl:template>
<xsl:template match="ClassicRepairPartBasic">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>
<xsl:value-of select="position()" />
<xsl:text>.</xsl:text>
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
<xsl:value-of select="key('PartDtl', GuideNumber/@number)/PartDesc" />
<xsl:apply-templates select="RepairInfoList/ClassicRepairInfoSPVehicle/Comment"
/>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</xsl:template>
<xsl:template match="Comment">
<xsl:text> </xsl:text>
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>