[Home] [By Thread] [By Date] [Recent Entries]
Hi Wendell, (and others)
Thank you very much for a very thorough answer. I think it starts to fall into place.... However it would still be beneficial for me to go through - as you suggest - a simple extract from the project. As suggested, I've included a simple XML instance and XSL stylesheet. The stylesheet consists of to template matches: The method 1 seems to me to be the logical approach. Match the ManureTypeCollection and iterate over each ManureTypeStructure/ManureTypeCode. For each code use the key to look up the corresponding ManureTypeName. The problem here is that the same code is being looked up twice and returned twice, which should only be once. in Method 2 (a colleagues tip) the result is actually what I want - the names are just returned once! but the approach seems not right to me - it seems to work the other way around, by first matching the lookup names, and returning them if a corresponding code is found, that is not optimal is it? It would be great if someone could describe to me: 1. the best way of returning the ManureTypeNames once. (comment on method 1 and 2) 2. describe the code line by line especially if it uses the Munchean method on beforehand thanks a lot! - Christian XSL: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:eih="http://rep.oio.dk/glrchr.dk/eih/xml/schemas/2005/03/01/" xmlns:gr="http://rep.oio.dk/glrchr.dk/goedningsregnskab/xml/schemas/2006/05/0 1/" > <xsl:key name="ManureType" match="gr:ManureTypeName" use="../gr:ManureTypeCode"/>
<!-- METHOD 1 - writes the text twice, returns: AjleAjleFast
gxdningFast gxdning -->
<xsl:template match="eih:ManureTypeCollection">
<xsl:for-each select="eih:ManureTypeStructure/gr:ManureTypeCode">
<xsl:value-of select="key('ManureType',node())"/>
</xsl:for-each>
</xsl:template> <!-- METHOD 2 - writes out the text once, as wanted, returns:
Fast gxdning, Ajle, -->
<xsl:template match="eih:ManureTypeCollection">
<xsl:for-each select="key('ManureType',
eih:ManureTypeStructure/gr:ManureTypeCode)">
<xsl:value-of select="node()"/>
<xsl:if test="not(position()='last')"><xsl:text>,
</xsl:text></xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>XML instance:
<?xml version="1.0" encoding="UTF-8"?>
<eih xmlns:eih="http://rep.oio.dk/glrchr.dk/eih/xml/schemas/2005/03/01/"
xmlns:gr="http://rep.oio.dk/glrchr.dk/goedningsregnskab/xml/schem
as/2006/05/01/">
<!-- Codes and data -->
<eih:ManureTypeCollection>
<eih:ManureTypeStructure>
<gr:ManureTypeCode>5</gr:ManureTypeCode>
<gr:ElementIdentifier>N</gr:ElementIdentifier>
<gr:ElementQuantity>17.0</gr:ElementQuantity>
</eih:ManureTypeStructure>
<eih:ManureTypeStructure>
<gr:ManureTypeCode>5</gr:ManureTypeCode>
<gr:ElementIdentifier>P</gr:ElementIdentifier>
<gr:ElementQuantity>0.6</gr:ElementQuantity>
</eih:ManureTypeStructure>
<eih:ManureTypeStructure>
<gr:ManureTypeCode>4</gr:ManureTypeCode>
<gr:ElementIdentifier>N</gr:ElementIdentifier>
<gr:ElementQuantity>17.5</gr:ElementQuantity>
</eih:ManureTypeStructure>
<eih:ManureTypeStructure>
<gr:ManureTypeCode>4</gr:ManureTypeCode>
<gr:ElementIdentifier>P</gr:ElementIdentifier>
<gr:ElementQuantity> 6.3</gr:ElementQuantity>
</eih:ManureTypeStructure>
<eih:ManureTypeStructure>
<gr:ManureTypeCode>3</gr:ManureTypeCode>
<gr:ElementIdentifier>N</gr:ElementIdentifier>
<gr:ElementQuantity> 65.3</gr:ElementQuantity>
</eih:ManureTypeStructure>
<eih:ManureTypeStructure>
<gr:ManureTypeCode>3</gr:ManureTypeCode>
<gr:ElementIdentifier>P</gr:ElementIdentifier>
<gr:ElementQuantity> 26.3</gr:ElementQuantity>
</eih:ManureTypeStructure>
<eih:ManureTypeStructure>
<gr:ManureTypeCode>3</gr:ManureTypeCode>
<gr:ElementIdentifier>P</gr:ElementIdentifier>
<gr:ElementQuantity> 16.3</gr:ElementQuantity>
</eih:ManureTypeStructure>
</eih:ManureTypeCollection> <!-- look up information for the codes -->
<eih:XImanureTypeCollection>
<eih:XImanureTypeStructure>
<gr:ManureTypeCode>4</gr:ManureTypeCode>
<gr:ManureTypeName>Fast gxdning</gr:ManureTypeName>
</eih:XImanureTypeStructure>
<eih:XImanureTypeStructure>
<gr:ManureTypeCode>5</gr:ManureTypeCode>
<gr:ManureTypeName>Ajle</gr:ManureTypeName>
</eih:XImanureTypeStructure>
</eih:XImanureTypeCollection>
</eih>On 6/5/06, Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> wrote: Hi Christian,
|

Cart



