this question relates to
XSLT to generate html tags specified in XML
where I had an xml docment and used an xsl to generate html tags using
<xsl:element name="{Type}" >
the problem I have is that I want to specify some html attributes in my xml for example
<Page>
<ID>Site</ID>
<Object>
<ID>PostCode</ID>
<Type>div</Type>
<Attributes>
<Attribute name="class">TestStyle</Attribute>
<Attribute name="id">TestDiv</Attribute>
</Attributes>
<Class>display-label</Class>
<Value>PostCode</Value>
</Object>
</Page>
So does any one know how I could populate the xsl:element with the two attributes using xsl?
Thanks
Building from the stylesheet that I posted in the previous question, within the element declaration you can iterate through each of the
Attributes/Attributeelements and construct the attributes for the element that you are constructing.You are “standing” on the
Objectelement node inside that for-loop, so you can then iterate over it’sAttributes/Attributeelements like this:Applied to your stylesheet:
This is an alternative way to achieve the same output, but in a little more delcarative fashion, using
apply-templatesinstead offor-each.