<stylesheet>

XSLT stylesheet definition

Core v2.2.0

Overview

The processor defines the XSLT stylesheet content for XML transformations. Must be used as a child element of . Supports XSLT 1.0 and 2.0 transformations with Saxon engine.

Usage Examples

Example 1: Basic XML transformation

example-1.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<xslt>
  <stylesheet>
    <![CDATA[
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="/">
        <html>
          <head><title>Product Catalog</title></head>
          <body>
            <h1>Products</h1>
            <xsl:for-each select="//product">
              <div class="product">
                <h2><xsl:value-of select="name"/></h2>
                <p>Price: $<xsl:value-of select="price"/></p>
              </div>
            </xsl:for-each>
          </body>
        </html>
      </xsl:template>
    </xsl:stylesheet>
    ]]>
  </stylesheet>
  <xml>${sourceXml}</xml>
</xslt>
</config>

Example 2: Data transformation with filtering

example-2.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<xslt>
  <stylesheet>
    <![CDATA[
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="/">
        <products>
          <xsl:for-each select="//product[price > 100]">
            <xsl:sort select="price" order="ascending"/>
            <product>
              <id><xsl:value-of select="@id"/></id>
              <name><xsl:value-of select="name"/></name>
              <price><xsl:value-of select="price"/></price>
              <category><xsl:value-of select="category"/></category>
            </product>
          </xsl:for-each>
        </products>
      </xsl:template>
    </xsl:stylesheet>
    ]]>
  </stylesheet>
  <xml>${productCatalog}</xml>
</xslt>
</config>

Example 3: Complex transformation with parameters

example-3.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<def var="currency">USD</def>
<def var="discountRate">0.1</def>

<xslt>
  <stylesheet>
    <![CDATA[
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:param name="currency"/>
      <xsl:param name="discountRate"/>
      
      <xsl:template match="/">
        <catalog>
          <xsl:for-each select="//product">
            <item>
              <name><xsl:value-of select="name"/></name>
              <originalPrice><xsl:value-of select="price"/></originalPrice>
              <discountedPrice>
                <xsl:value-of select="price * (1 - $discountRate)"/>
              </discountedPrice>
              <currency><xsl:value-of select="$currency"/></currency>
            </item>
          </xsl:for-each>
        </catalog>
      </xsl:template>
    </xsl:stylesheet>
    ]]>
  </stylesheet>
  <param name="currency">${currency}</param>
  <param name="discountRate">${discountRate}</param>
  <xml>${sourceData}</xml>
</xslt>
</config>

Example 4: HTML to structured data

example-4.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<xslt>
  <stylesheet>
    <![CDATA[
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="/">
        <structuredData>
          <xsl:for-each select="//div[@class='product']">
            <product>
              <title><xsl:value-of select="h2/text()"/></title>
              <price><xsl:value-of select="span[@class='price']/text()"/></price>
              <description><xsl:value-of select="p[@class='description']/text()"/></description>
              <image><xsl:value-of select="img/@src"/></image>
            </product>
          </xsl:for-each>
        </structuredData>
      </xsl:template>
    </xsl:stylesheet>
    ]]>
  </stylesheet>
  <xml>
    <html-to-xml>
      <http url="https://shop.example.com/products"/>
    </html-to-xml>
  </xml>
</xslt>
</config>

Parameters

Important Notes

Related Processors