Cascaderen (XSL)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Kan ik verschillende bewerkingen cascaderen? Oftewel concatenate, pipe of sequential iets? Ik word tureluurs dat alle bewerking in een apart bestand zit.

Inventaris

  • Include: Je lijkt XSL-transformaties te kunnen aanroepen vanuit een ander XSL-bestand middels import - Amper een oplossing, denk ik [1]
  • Modes: Dit lijkt mogelijk te zijn door de output van de ene bewerking in een variabele te stoppen, en die te gebruiken als input voor de volgende bewerking. Zie hieronder
  • FXSL: FXSL lijkt een library te zijn voor XSL waarmee dat kan [2],[3]
  • Integreren: In de praktijk kun je waarschijnlijk veel meer transformaties in één bestand proppen dan je denkt. Zie voorbeeld hieronder.

Modes

Voorbeeld [4]:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ext="http://exslt.org/common"
    exclude-result-prefixes="ext xsl">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>


<!--
   ============================== 
   Gewone identity transformation
   ==============================
-->

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


<!--
   ==========================================================
   Associëer de toplevel-node met variable vrtfPass1
   ==========================================================
-->

 <xsl:template match="/">
  <xsl:variable name="vrtfPass1">
   <xsl:apply-templates select="node()"/>
  </xsl:variable>


<!-- 
   ======================================
   * Executeer de templates hierboven
   * Associëer de output met mode "pass2"
   ======================================
-->

  <xsl:apply-templates mode="pass2"
   select="ext:node-set($vrtfPass1)/node()"/>
 </xsl:template>

<!--
   =========================================
   Bewerk deze nieuwe node-set
   =========================================
-->

 <xsl:template match="/*">
     <xsl:copy>
       <xsl:copy-of select="@*"/>
       <one/>
     <xsl:apply-templates/>
     </xsl:copy>
 </xsl:template>

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

 <xsl:template match="/*/one" mode="pass2" >
     <xsl:call-template name="identity"/>
      <two/>
 </xsl:template>
</xsl:stylesheet>

Integreren

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ext="http://exslt.org/common"
    exclude-result-prefixes="ext xsl">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
   <xsl:strip-space elements="*"/> <!-- Belangrijk! Anders wordt 't een zooitje -->


<!-- 
   ===========================================
   Identity Transformation
   ===========================================
-->

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

<!-- 
   ==============================================
   Remove unwanted stuff
   ==============================================
-->

<xsl:template match="Assortment" />
<xsl:template match="Availability" />
<xsl:template match="Costs" />


<!-- =========================================== -->
<!-- Alle attributen omfietsen naar subelementen -->
<!-- =========================================== -->

   <xsl:template match="@*">
      <xsl:element name="{name(..)}_{name()}">
         <xsl:value-of select="." />
      </xsl:element>
   </xsl:template>


<!-- 
   ===========================================
   Differentiate tagnames
   ===========================================
   Only needed for Item//Description
-->

<xsl:template match="Item//Description">
   <item_description> <xsl:apply-templates/></item_description>
</xsl:template>


<!--
   ==============================================
   Parenting
   ==============================================
   Remove a bunch of 'parents'. At least one of
   these parents (Item) is refered to here above,
   so appearantly, transformations get processed
   in order.
-->

<xsl:template match="Discounts">      
    <xsl:apply-templates select="*"/>
</xsl:template>

<xsl:template match="Item">      
    <xsl:apply-templates select="*"/>
</xsl:template>

<xsl:template match="Unit">      
    <xsl:apply-templates select="*"/>
</xsl:template>

<xsl:template match="ItemPrices">      
    <xsl:apply-templates select="*"/>
</xsl:template>


<!-- 
   ===========================================
   Close
   ===========================================
-->
</xsl:stylesheet>

Bronnen