Using node parameters in named templates using XSLT 2.0

Go To StackoverFlow.com

0

I am attempting to use XSLT 2.0 to generate a XHTML view of content encoded in RDF/XML. I would like to use named templates to modularize and simply my XSL stylesheet.

My initial attempt to pass nodes to my named templates is clearly not working.

I am new to XSLT, but web searches have led me to believe my problem is because XSL is passing a result tree fragment (RTF) instead of a node. This is definitely an issue with XSLT 1.0, but is it an issue with 2.0? Unfortunately, it is non-obvious to me how to apply solutions posed to XSL node-passing question on stackoverflow and similar sites.

Is what I want to do even possible with XSLT 2.0?

What direction should I take?

<xsl:template match="rdf:RDF">
  <xsl:variable name="report" select="owl:NamedIndividual[@rdf:about='&ex;quality_report']"/>
  <table>
    <tr>
      <xsl:for-each select="owl:NamedIndividual[@rdf:about=$report/mdsa:hasProductScope/@rdf:resource]">
        <td>
          <xsl:call-template name="quality_label">
            <xsl:with-param name="product_scope" select="."/>
          </xsl:call-template>
        </td>
      </xsl:for-each>
    </tr>
  </table>
</xsl:template>

<xsl:template name="quality_label">
  <xsl:param name="product_scope"/>
  <table>
    <xsl:for-each select="owl:NamedIndividual[@rdf:about=$product_scope/mdsa:scopeDataEntity/@rdf:resource]">
      <tr><td>
      <!-- CALL ANOTHER NAMED TEMPLATE TO PROCESS DATA ENTITY -->
      </td></tr>
    </xsl:for-each>
  </table>
</xsl:template>

I also tried it with

<xsl:with-param name="entity" select="current()"/>

example RDF/XML

  <owl:NamedIndividual rdf:about="&ex;modis_aqua_aod_product_scope">
    <rdf:type rdf:resource="&mdsa;ProductScope"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_global_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_global_land_only_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_e_conus_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_w_conus_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_central_america_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_south_america_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_s_south_america_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_africa_above_equator_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_equatorial_africa_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_africa_below_equator_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_europe_mediterranean_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_eurasian_boreal_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_east_asia_midlatitudes_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_peninsular_southeast_asia_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_indian_subcontinent_data_entity"/>
    <mdsa:scopeDataEntity rdf:resource="&ex;modis_aqua_australian_continent_data_entity"/>
    <mdsa:scopeVariable rdf:resource="urn:nasa:eosdis:variable:MYD08_D3.051:Optical_Depth_Land_And_Ocean_Mean"/>
  </owl:NamedIndividual>

  <owl:NamedIndividual rdf:about="&ex;quality_report">
    <rdf:type rdf:resource="&mdsa;QualityReport"/>
    <dcterms:identifier rdf:datatype="http://www.w3.org/2001/XMLSchema#string">01ffc5bfba33e7139ffbd4b7185f9b0e</dcterms:identifier>
    <mdsa:hasProductScope rdf:resource="&ex;modis_terra_aod_product_scope"/>
    <mdsa:hasProductScope rdf:resource="&ex;modis_aqua_aod_product_scope"/>
  </owl:NamedIndividual>
2012-04-03 19:53
by LokiPatera


0

The element you are passing to your named template is an element named owl:namedIndividual. The called template tries to find a child of this element which is also called owl:namedIndividual, but your owl:namedIndividual elements have no children with this name.

This kind of problem can be easily diagnosed if you get into the habit of using the "as" attribute on parameter and variable declarations, for example as="element(owl:namedIndividual)". This tends to make the errors stand out and gives better diagnostics; if you combine this with schema-awareness you will even get compile-time notification of your mistake.

2012-04-03 21:09
by Michael Kay
What is 'schema-awareness'? Is that part of Stylus Studio's XML Schema Tools - LokiPatera 2012-04-04 20:56
"Schema awareness" refers to the ability in XSLT 2.0 to write stylesheets that import a schema and make use of type definitions in the schema to optimize the stylesheet and provide better type checking, allowing mistakes like this one to be detected more easily - Michael Kay 2012-04-06 18:31