Re: Repeating Code
<xsl:template name="COLDATA"> <xsl:with-param name="selectval"/> <COL> <DATA> <xsl:value-of select="$selectval" /> </DATA> </COL> </template>
The only thing is that it only reduces my 5 line <COL> node into three xsl:call-template items instead of just one (because of the parameter). But I think it's neater, it separates the XML output from the xsl processing instructions. Maybe not faster, but that's a different test altogether.
The long email I had typed (it seemed a waste not to send it) is below.
On 10/10/2005, at 6:05 PM, Ragulf Pickaxe wrote:
So essentially it's going through each of the FieldRef's in the XML and generating a <ROW> with a whole bunch of <COL> data. The selects that I've got take into account a whole raft of either parent nodes, child nodes and ancestor nodes as well. So any solution has to be flexible in that sense.
Sure. The total file this works on is over 20,000 lines long, and the xsl:for-each finds a <chunk> node that could be at any level in the xml, and under any different other nodes. So that's why the xsl:for-each has the descendant option in it :
<xsl:for-each select="/FMPReport/File/descendant::Chunk [@type='FieldRef']">
So one example of the XML is :
<FMPReport link="Summary.xml" type="Report" creationDate="18/09/2005" creationTime="3:25:52 PM">
<File name="BankAccounts" path="10.0.1.9">
<BaseTable id="32779" name="BankAccount" records="7">
<Field id="40" name="Currency" dataType="Text" fieldType="Normal">
<Field id="7" name="gCurrency" table="BankAccountPreferences" />
There are about a dozen different types at the <BaseTableCatalog> level, and each one has it's own structure, and then it's own possible way of using the <Chunk> node. For example, you can have a chunk node as a child of the <Field> node, or the <AutoEnter>, or even other child nodes.
This is one particular xslt (there are 19 files so far that I'm developing for this solution), and this one contains 28 <xsl:value-of select...> items. Some are references to the parent item to get some perspective on how deep into the XML this chuck node was found :
<xsl:value-of select="name(..)" /> <xsl:value-of select="name(../..)" /> <xsl:value-of select="name(../../..)" /> ...
There are a bunch to grab the ancestor values :
<xsl:value-of select="ancestor::Calculation/@name" />
<xsl:value-of select="ancestor::BaseTable /@id" />
<xsl:value-of select="ancestor::BaseTable /@name" />
<xsl:value-of select="ancestor::Field/ @id" />
<xsl:value-of select="ancestor::Field/ @name" />
and more to grab the chunk data itself :
<xsl:value-of select="./@type"/> <xsl:value-of select="./Field/@id"/> <xsl:value-of select="./Field/@name"/> <xsl:value-of select="./Field/@table"/>
in total 28 for this particular xslt file.
Do they have to be in a particular order?
They don't have to be in a particular order, but they're all matched to a header row above, so I'd have to be able to have the same order for both the header row and the data row that is this xsl:template.
This isn't a requirement to make the xslt work, I was just wondering if it was possible to do. Is it possible to pass a parameter to a template that you can use in a select? So you could have :
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format