Search code examples
xsltimportapply-templates

passing parameter to parsing of imported file


In parsing a WSDL, I come across many wsdl:import and xsd:import elements. I would like to parse the imports and pass the @location or @schemaLocation to the parser.

The intent is to have the file list grow when an imported file imports a file for example filea.wsdl;filez.xsd;filev.xsd. This way I can eliminate a previously imported file.

I would think something along along these lines:

<xsl:param name="file-list"/>

<xsl:template match="/">
    <xsl:param name="file-list"/>
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="wsdl:import">
    <xsl:apply-templates select="document(@location)">
        <xsl:with-param name="file-list" select="concat($file-list, ';', @location)`"/>
    </xsl:apply-templates>
</xsl:template>

Solution

  • Your basic idea seems to be fine. You just need to pass the the file-list parameter along when applying templates, so:

    1. add a <xsl:with-param name="file-list" value="$file-list"/> to the xsl:apply-templates in your first template to actually pass the parameter, and
    2. add a <xsl:param name="file-list"/> to your second template to introduce the parameter there.