Re: [xsl] fastest way to do projection in xsl

Subject: Re: [xsl] fastest way to do projection in xsl
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Thu, 07 Nov 2002 02:01:56 +0100
Hello Kasper,

a nice and short stylesheet already solves your problem. It contains only of the identity transformation template (copies everyting to the output, that is matched), a template for all (to not copy the view) and a template matching on the project elements, that contains the important logic.

<xsl:template match="all">
    <xsl:apply-templates select="projects"/>
</xsl:template>

<xsl:template match="project">
<xsl:copy>
<xsl:variable name="thisProject" select="."/>
<xsl:for-each select="/all/view/columns/measure">
<xsl:apply-templates select="$thisProject/measure[@name = current()/@name]"/>
</xsl:for-each>
</xsl:copy>
</xsl:template>


<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

I think it's easy to understand, isn't it?

Regards,

Joerg

Kasper Nielsen wrote:
Hello,

Basicly what im looking for is how to (fastest possible way) do a project
(relational algebra) operation on a long list of relations in xsl

Let's say I have this document

<all>

    <view name="economy">
        <columns>
            <measure name="economy_estimate"/>
            <measure name="economy_actual"/>
            <measure name="responsible"/>
        </columns>
    </view>

    <projects>
        <project>
            <measure name="responsible"> kav </measure>
            <measure name="economy_actual">991233</measure>
            <measure name="economy_estimate">881123</measure>
            <measure name="schedule_actual">123</measure>
            <measure name="schedule_estimate">823</measure>
        </project>
        <project>
            <measure name="responsible"> pjc </measure>
            <measure name="economy_actual">77123123</measure>
            <measure name="economy_estimate">44123123</measure>
            <measure name="schedule_actual">723</measure>
            <measure name="schedule_estimate">923</measure>
        </project>
        ..... 100's of other projects....
    </projects>
</all>

how do I transform this document into something like this with xsl
The order between measures is as defined in the view part, ie (estimate
before actual) before responsible

<projects>
  <project>
    <measure name="economy_estimate">881123</measure>
    <measure name="economy_actual">991233</measure>
    <measure name="responsible"> kav </measure>
  </project>
  <project>
    <measure name="economy_estimate">44123123</measure>
    <measure name="economy_actual">77123123</measure>
    <measure name="responsible"> pjc </measure>
  </project>
</projects>


regards Kasper




XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list





XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


Current Thread