[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Repeating Code

Subject: Re: Repeating Code
From: Nicholas Orr <nick@xxxxxxxxxxx>
Date: Mon, 10 Oct 2005 19:41:52 +1000
nicholas orr
Thanks ragulf. After typing a long email, I think I've figured it out. I think I can just pass the select option to a template that is :

    <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.

Thanks,
Nick


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.



Could we get an example of the the XML in question? Just a small one, but which adequately descripes the structure. Some might give a good solution to that one.

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">
<BaseTableCatalog>
<BaseTable id="32779" name="BankAccount" records="7">
<FieldCatalog>
<Field id="40" name="Currency" dataType="Text" fieldType="Normal">
<AutoEnter>
<DisplayCalculation>
<Chunk type="FieldRef">
<Field id="7" name="gCurrency" table="BankAccountPreferences" />
</Chunk>
</DisplayCalculation>
</AutoEnter>
</Field>


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.


Also, from what I understood, the <xsl:value-of select...> where for 30 different selects, whereas others have understood them to be only two different ones. Which of us are correct here?

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[1]/@name" />
<xsl:value-of select="ancestor::BaseTable [1]/@id" />
<xsl:value-of select="ancestor::BaseTable [1]/@name" />
<xsl:value-of select="ancestor::Field[1]/ @id" />
<xsl:value-of select="ancestor::Field[1]/ @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 :

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.