I am working on the following xml file:
<relational:BaseTable name="Table1">
<columns name="Column1" Type="Number" </columns>
<columns name="Column2" Type="Date" </columns>
....
I want create a CSV file like this
Table1, Column1, Number
Table1, Column1, Date
Table2, ...
I have figured out how to loop through the xml and format the output as csv. What the code below is missing is a way to repeat the name of the tables at the start of each line. I cannot figure out how to reference the “name” attribute of the parent (relational:BaseTable) tag.
<xsl:for-each select="relational:BaseTable">
<xsl:for-each select="columns">
<xsl:value-of select="@name"/>,<xsl:value-of select="@type"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:for-each>
Thanks
To access the
BaseTable‘s@nameattribute, you just need to move up the hiearchy a bit:Note that you would need to do this even if the attribute names weren’t the same, since the current reference context is a
columnselement.I would also suggest simplifying the above line into a single
value-of: