xsl-list
[Top] [All Lists]

Re: [xsl] XSLT Streaming - How to consume same node twice.

2016-08-23 18:08:13
Thanks Michael.
i looked at the code like million times wondering why it isnt working..
Vasu

On Tue, Aug 23, 2016 at 6:03 PM, Michael Kay mike(_at_)saxonica(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
You're so close: you've used xsl:fork, which is the way to tackle this, but
you have used it wrong.

Replace

<xsl:fork>
  <xsl:sequence>
    ....
  </xsl:sequence>
</xsl:fork>
<xsl:fork>
  <xsl:sequence>
    ....
  </xsl:sequence>
</xsl:fork>

by

<xsl:fork>
  <xsl:sequence>
    ....
  </xsl:sequence>
  <xsl:sequence>
    ....
  </xsl:sequence>
</xsl:fork>

Of course, xsl:fork compromises streaming: essentially, it allows the input
to be streamed, but the output will typically need to be buffered so it can
be reassembled in the right order.

Michael Kay
Saxonica


On 23 Aug 2016, at 21:02, Mailing Lists Mail daktapaal(_at_)gmail(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:


Hi All,

I want to consume one node twice. If I were using a URL for streaming, I
know how to do this, but when I am using an XSL to be run with an XML, i am
having difficulties doing the same

I have the following XML


<RootNode>
<Groups>
<Group>
<specifics>
<specific>Subgroup1</specific>
<specific>Subgroup2</specific>
</specifics>
<Group_Detail>
<GroupIdentifier>G1</GroupIdentifier>
</Group_Detail>
</Group>
<Group>
<specifics>
<specific>Subgroup3</specific>
<specific>Subgroup4</specific>
</specifics>
<Group_Detail>
<GroupIdentifier>G1</GroupIdentifier>
</Group_Detail>
</Group>
<Group>
<specifics>
<specific>Subgroup1</specific>
<specific>Subgroup2</specific>
</specifics>
<Group_Detail>
<GroupIdentifier>G3</GroupIdentifier>
</Group_Detail>
</Group>
<Group>
<specifics>
<specific>Subgroup5</specific>
<specific>Subgroup6</specific>
</specifics>
<Group_Detail>
<GroupIdentifier>G2</GroupIdentifier>
</Group_Detail>
</Group>

</Groups>
</RootNode>

XSLT that we need to run on this is :


<xsl:transform version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:mode name="stream" streamable="yes" on-no-match="shallow-copy"/>
<xsl:output method="xml" indent="yes"/>

  <xsl:template match="/" mode="stream">

<xsl:result-document href="fileout.xml">
<xsl:apply-templates mode="stream"/>
</xsl:result-document>
</xsl:template>
<xsl:template match="Groups" mode="stream">
<xsl:fork>
<xsl:sequence>
<xsl:copy>
<xsl:for-each select="Group/copy-of(.)">
<Formatted-Group groupId="{Group_Detail/GroupIdentifier}">
<xsl:copy-of select="specifics"/>
</Formatted-Group>
</xsl:for-each>
</xsl:copy>
</xsl:sequence>
</xsl:fork>
<xsl:fork>
<xsl:sequence>
<aggregated>
<xsl:for-each select="Group/copy-of(.)">
<Aggregated groupId="{Group_Detail/GroupIdentifier}">
<xsl:copy-of select="specifics"/>
</Aggregated>
</xsl:for-each>
</aggregated>
</xsl:sequence>
</xsl:fork>
</xsl:template>
</xsl:transform>


I am sure this is wrong.. but what can be done to correct this.. I know,
that if I had a URL i could stream , then I would have written

<xsl:stream href="{$fileHref}">

<aggregated>
<xsl:for-each select="/RootNode/Groups/Group/copy-of(.)">
<Aggregated groupId="{Group_Detail/GroupIdentifier}">
<xsl:copy-of select="specifics"/>
</Aggregated>
</xsl:for-each>
</aggregated>


</xsl:stream>



Is there something similar I can use when I am not using File URL as the
input?


Dak Tapaal


XSL-List info and archive
EasyUnsubscribe (by email)


XSL-List info and archive
EasyUnsubscribe (by email)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>