Re: Need help with this transformation

"swegele" <[email protected]>
Newsgroups gmane.comp.mozilla.devel.layout.xslt
Organization http://groups.google.com
Message-ID <[email protected]>
Thanks Martin!

1.  Point noted on other group to post to...newbie mistake.
2.  Result1 & Result2 coincide with object properties that need to be
populated from xml...but I see your point about doing a list in a best
practices sense.
3.  In this case we do know that there will only be 2 results so
deviation was merely the difference between the two...another object
property that needs to be populated.

Big picture, this is a specific XSLT that is designed to transform
information into a form that can be imported into an object.  Xslt is
bridging the gap between .txt output from a machine and properties of
an object that can be populated via reflection from xml document.
Since XSLT isn't compiled with the assembly, it can flex to account for
the unknown.


On Oct 24, 7:42 am, Martin Honnen <[email protected]> wrote:
> swegele wrote:
> > *** I am still cuttin my teeth on thinking like XSL
> > (declaritive/functional) So I could use some help figuring out the
> > pattern to solve this problem of coallation and computation.
> > To be honest if I solve the coallation problem I think I will be 90%
> > there no?The grouping can be solve like this
>
> <xsl:stylesheet
>    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>    version="1.0">
>
> <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
>
> <xsl:key name="request-evidence" match="Result"
> use="concat(RequestNumber, '_', EvidenceNumber)"/>
>
> <xsl:template match="Results">
>    <xsl:copy>
>      <xsl:apply-templates select="Result[generate-id() =
> generate-id(key('request-evidence', concat(RequestNumber, '_',
> EvidenceNumber))[1])]" mode="group"/>
>    </xsl:copy>
> </xsl:template>
>
> <xsl:template match="Result" mode="group">
>    <xsl:copy>
>      <xsl:apply-templates select="RequestNumber | EvidenceNumber"/>
>      <xsl:variable name="group" select="key('request-evidence',
> concat(RequestNumber, '_', EvidenceNumber))"/>
>      <Result-List>
>        <xsl:apply-templates select="$group/Result"/>
>      </Result-List>
>      <Deviation>
>        <!-- compute deviation here -->
>      </Deviation>
>    </xsl:copy>
> </xsl:template>
>
> <xsl:template match="@* | node()">
>    <xsl:copy>
>      <xsl:apply-templates select="@* | node()"/>
>    </xsl:copy>
> </xsl:template>
>
> </xsl:stylesheet>
>
> It gives the result you want beside my choice to not put an index into
> element names (e.g. Result1, Result2) which is bad XML design but use a
> Result-List parent element so you get e.g.
>
> <Results>
>    <Result>
>      <RequestNumber>1</RequestNumber>
>      <EvidenceNumber>1</EvidenceNumber>
>      <Result-List>
>        <Result>3.1</Result>
>        <Result>3.2</Result>
>      </Result-List>
>      <Deviation/>
>    </Result>
>    <Result>
>      <RequestNumber>2</RequestNumber>
>      <EvidenceNumber>1</EvidenceNumber>
>      <Result-List>
>        <Result>3.1</Result>
>        <Result>3.1</Result>
>      </Result-List>
>      <Deviation/>
>    </Result>
> </Results>
>
> I am not sure how you want to compute the Deviation element content, in
> your example it just seems to be the difference of the two Result
> elements you have in each group but I am not sure your real XML input
> has only two Result elements for each group.
>
> Note that general XSLT coding questions are better asked in a generic
> XML group (like comp.text.xml) or XSLT list, this group is mainly for
> specific problems with the XSLT implementation in Mozilla.
>
> --
> 
>         Martin Honnen
>        http://JavaScript.FAQTs.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.