Re: [xsl] Re parsing element data generated by XSLT within the same stylesheet

Subject: Re: [xsl] Re parsing element data generated by XSLT within the same stylesheet
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 29 Dec 2009 13:50:15 -0500
At 2009-12-29 13:31 -0500, David A. Lee wrote:
I'm trying to learn XSLT (better).

Keep in mind there are instructor-led XSLT/XQuery training classes coming up in Europe and California (I've mentioned them on my home page and will announce them in the new year):


http://www.CraneSoftwrights.com/s/

I'm working with an existing complicated stylesheet that I need to make changes to.
I have a working solution where I output the XSLT piped to XQuery (which I know better) but I'd like to do the whole thing in XSLT.


The basic concept/solution I'm looking for is: is it possible, and how, to re-process generated elements that are not in the source document.

Yes, by putting those elements into a variable and then acting on the variable contents.


Simplified example: suppose I have a template like this. Suppose I have LOTS of templates like these.

<xsl:template match="v3:renderMultiMedia/v3:caption">
       <p>
           <xsl:call-template name="styleCodeAttr">
               <xsl:with-param name="styleCode" select="@styleCode"/>
               <xsl:with-param name="additionalStyleCode"
               select="'MultiMediaCaption'"/>
           </xsl:call-template>
           <xsl:apply-templates select="@*[not(local-name(.)='styleCode')]"/>
           <xsl:apply-templates mode="mixed" select="node()"/>
       </p>
</xsl:template>

What I'd like to do is change every <p>XXX</p> into XXX&#10;

<xsl:variable name="intermediate" as="element(p)*"> <xsl:apply-templates/><!--this is what you are doing now--> </xsl:variable> <xsl:for-each select="$intermediate"> <xsl:copy-of select="node()"/> <xsl:text> </xsl:text> </xsl:for-each>

or.....

  <xsl:variable name="intermediate" as="element(p)*">
    <xsl:apply-templates/><!--this is what you are doing now-->
  </xsl:variable>
  <xsl:apply-templates select="$intermediate" mode="change-p-to-nl"/>
...
<xsl:template mode="change-p-to-nl" match="p">
  <xsl:copy-of select="node()"/>
  <xsl:text>
</xsl:text>
</xsl:template>

Of course you'll have to take away the as= constraint if in fact you don't always have <p> elements.

Obviously I can edit every template to change how it generates the
output XML, but I'm wondering is there a way to do this in XSLT by saying
"Re-parse the generated XML by this template".

By acting on the generated XML that was placed in a variable rather than in the result tree.


I hope this helps.

. . . . . . . . . . . . Ken

--
UBL and Code List training:      Copenhagen, Denmark 2010-02-08/10
XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19
XSLT/XQuery/XPath training:   San Carlos, California 2010-04-26/30
Vote for your XML training:   http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread