Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Keys and select distinct - is that the solution ?

From: "Christian Rasmussen" <byggemandbob@--------->
To:
Date: 6/2/2006 10:39:00 PM
sorry I mean it is a one-to-many
- christian


On 6/3/06, Christian Rasmussen <byggemandbob@xxxxxxxxx> wrote:
First of all thanx to both of you for trying to help.
right now I am trying to apply your suggestions....

I am a quite newbie and I am not not sure I understand the muenchian
method,
but regarding your last statement Wendell Piez:



I believe it is a many to many relation:



If you look back on my input, you can see that the code 5 for instance
is listed two times in one of the structures (aka tables), and I have
to take that value and look it up somewhere else in the document (aka
another table) and return the value "Ajle".

That is a one to many....



well, I'll go work on those two other suggestions...



- Christian



On 6/3/06, Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> wrote:
> Dear Christian,
>
> XSLT 2.0 has a distinct-values() function, which
> is useful for this kind of thing, along with its native grouping
constructs.
>
> In XSLT 1.0, it's a fairly standard grouping
> problem. Usually we de-duplicate a set of nodes
> by determining which members of the set are the
> first (in document order) with a given value. In
> your case, you have to decide whether the value
> you want to check is the code value, or the name
> (if they're in a strict one-to-one relation it
> doesn't matter, and the value is more convenient).
>
> Keys are a very convenient way to de-duplicate
> when your data set is large. You can use brute XPath if not.
>
> So:
>
> <xsl:key name="manure-type-codes" match="gr:ManureTypeCode"
>    use="."/>
>
> <xsl:key name="manure-type-names" match="gr:ManureTypeName"
>    use="../gr:ManureTypeCode"/>
>
> <xsl:template match="gr:ManureTypeCode">
>    <xsl:if test="generate-id() =
generate-id(key('manure-type-codes',.)[1])">
>      <!-- tests true only if the ManureTypeCode is the first with this
value,
>           more or less the equivalent of 'select distinct' -->
>      <xsl:copy-of select="key('manure-type-names',.)"/>
>    </xsl:if>
> </xsl:template>
>
> If the codes and names are in a one-to-many or
> many-to-many relation, we have to think harder.
>
> I hope this helps!
> Wendell
>
> At 05:55 PM 6/2/2006, you wrote:
> >Hi experts,
> >
> >I've been struggling with a problem for several hours now, and I
> >cannot find the solution:
> >I have an XML document with a elements grouped in elements and
> >ManureTypeCodes and datavalues as siblings.
> >Then I have - somewhere else - in the document lookup information
> >(labels) for the codes.
> >These are grouped in elements of ManureTypeCodes and ManureTypeNames
> >
> >I want to create a template rule which matches the codes and looks up
> >the corresponding name and ONLY writes the
> >ManureTypeName out once! In RDBMS I would use something like select
> >distinct when selecting the codes, but I dont know what the right
> >approach is in XSLT.
> >
> >can someone please help.... on before hand thank you!
> >
> >my XML:
> ><eih>
> >    <!-- 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: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:XImanureTypeStructure>
> >    </eih:XImanureTypeCollection>
> ></eih>
> >
> >
> >best regards,
> >
> >Christian Rasmussen
> >Denmark


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent