I am trying to understand a piece of XSLT code for a work project, but I just can't figure out what calls what and how the values are passsed in correctly.
I have this code, which uses the apply-templates element to select the first element in the document type element:
<xsl:apply-templates select="DocumentType[string(text())][1]" mode="XmlString">
<xsl:with-param name="name" select="'DocumentType'"/>
</xsl:apply-templates>
A parameter is then passed into the template, which assign the correct value. The name attribute in the with-param matches the param element here:
<xsl:template match="*" mode="XmlString">
<xsl:param name="name"/>
<!-- Check the "name" parameter : madantory / optional -->
<xsl:call-template name="MandatoryOrOptional">
<xsl:with-param name="name" select="$name"/>
<xsl:with-param name="value" select="."/>
</xsl:call-template>
</xsl:template>
But I'm not sure why and how the value gets passed. This is used repeatedly throughout the map whenever a value needs to be mapped.
Normally I would just create the tags needed and use the xsl:value-of element to get my desired value from the source document. If anyone could enlighten me as to how this code works in practice I would be grateful. The few times I've used apply-templates, I had already defined a template in my XSLT and then used the match attribute to apply it.