I’m calling a template:
<table>
<xsl:apply-templates select="data/pics/row"/>
</table>
The template is
<xsl:template match="row">
<tr>
<xsl:for-each select="td">
<td border="0">
<a href="{@referencddePage}">
<img src="{pic/@src}" width="{pic/@width}" height="{pic/@height}"/>
</a>
</td>
</xsl:for-each>
</tr>
</xsl:template>
My XML is:
<?xml version="1.0" encoding="iso-8859-8"?>
<?xml-stylesheet type="text/xsl" href="xslFiles\smallPageBuilder.xsl"?>
<data pageNo="3" referencePage="xxxxxxxxxxxxxxx.xml">
<pics>
<row no="0">
<td col="0">
<pic src="A.jpg" width="150" height="120"></pic>
</td>
</row>
</pics>
</data>
I want the line :a h r e f="{@referencddePage}" to get the input from
the root, :a h r e f= "{@referencddePage}"..., but I’m already in the <td level>.
In case it is a rule that the
@referencePageattribute is always an attribute of the top element, then it can always be accessed as:Therefore, in your code you’ll have:
I would recommend not to use
<xsl:for-each>and to use onlyand`. In this way the resulting XSLT code is more understandable and can be more easily modified in the future:When this transformation is applied on the provided XML document,
the wanted output is produced:
See how each template is so very simple. Also, the code is further simplified.
Now, instead of:
we have only: