This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
AW: for-each with included variable
- To: "'mail at jenitennison dot com'" <mail at jenitennison dot com>
- Subject: AW: [xsl] for-each with included variable
- From: "Machelett, Renato (FA.G+M-EP/ETK)" <fa-gm-renato dot machelett at daimlerchrysler dot com>
- Date: Fri, 20 Apr 2001 10:26:42 +0200
- Cc: xsl-list at lists dot mulberrytech dot com
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Jeni,
thank you for your input and your explanation. Your approach looks very
clear to me and I will give it a try. Unfortunately I don't think that I can
use keys because that doesn't seem to make sense in a global context and as
I understand I cannot use keys inside a template. But I might be wrong in
both cases. I'd appreciate any hint that helps me improve the design -
speaking of brevity, clarity and maintainability. Right now I find it very
hard to maintain; the stylesheets are very complex, very large (between 10
and 45K each - that's large for me), undocumented and I'm unfamiliar with
XSL. I'm not willing to pass the bundle on to other users in its current
state.
I would have liked to give more information, but the XML-file I'm working on
is confidential, apart from that it's huge - about 5 MB in size with
referenced elements, 20 MB with references resolved, and rather "deep".
So even giving the context for that little part means a major effort, but
I'm doing it anyway to give you an idea of what I'm talking about (I've
omitted about 80% additional descriptive elements). It was very kind of you
to explain in detail what's going on in that expression, and so I think you
deserve that I give my best shot at presenting how everything fits together.
You should disregard syntactical errors as the stuff below is "handcrafted"
for this mail and might not be 100% correct.
Currently for each target file (which usually contains type definitions,
interfaces and basic implementation in one of the desired programming
languages e.g. C or SDL) a basic template is used that mainly contains large
portions of CDATA (target framework and XSL expression) and a template to
replace several small parts (see XSL-skeleton below). That is used together
with a XML-control file to create a stylesheet that is "tailored" to operate
on a desired subset of that big XML-file. (Actually I decided that it's
better to reduce the XML-file to the desired subset and operate on that to
reduce complexity of expressions, but that's another, less painful story.)
That resulting stylesheet (lots of named templates and for-each expressions
like the one I presented)eventually generates the desired header-,
implementation or whatever target file it was designed for.
Of course I think I could use the XSL-skeleton, that I have to deal with
anyway (see below) to do something like this:
<xsl:include "FileWheremyOPTypeListIsDefinedAsText"/>
<![CDATA[<xsl:for-each select="]]>
<xsl:value-of select="$myOPTypeList"/>
<![CDATA["> do some impressive stuff ]]>
But that makes me feel sick. And I'd rather reduce the required
transformations from two to one than add complexity by stuffing the
CDATA-portions with more expressions.
Thanks again!
Renato
--- XML control file ---
<DesiredScope>
<SuperStructure>
WonderfulSetOfFunctions
</SuperStructure>
<SuperStructure>
IncredibleSetOfFunctions
</SuperStructure>
[..]
</DesiredScope>
--- basic XSL-skeleton, uses XML control file ---
<template match="/">
<xsl:variable name="myDesiredScope">
<xsl:if test="//SuperStructure"><xsl:text>[</xsl:text>
<xsl:for-each select="//SuperStructure">
<xsl:if test="position() != 1"><xsl:text> or </xsl:text></xsl:if>
<xsl:text>FBlockID='</xsl:text><xsl:value-of
select="@Id"/><xsl:text>'</xsl:text>
</xsl:for-each>
<xsl:text>]</xsl:text>
</xsl:if>
</xsl:variable>
<![CDATA[<?xml version="1.0" encoding="UTF-8"?> ..lots of target code and
XSLT expressions.. ]]>
<!-- several occurences of --><xsl:value-of select="$myDesiredScope"/>
<![CDATA[<?xml version="1.0" encoding="UTF-8"?> ..more code and XSLT
expressions.. ]]>
</template>
--- XML-skeleton with actual data ---
<..several superstructures, repeatedly..>
<Function>
<FunctionClass ..attributes..>
<Property>
<PropertyClass ..attributes..>
<PropertyParameter>
<PropertyOPType>
<OPTypeClass>
<Command ..attributes.. OPTypeRef="XType1">
</Command>
</OPTypeClass>
<PropertyOPTypeData>
<Level>
0
</Level>
<..sub-tree for data structure description..>
</PropertyOPTypeData>
</PropertyOPType>
<PropertyOPType>
<OPTypeClass>
<Command ..attributes.. OPTypeRef="XType1">
</Command>
</OPTypeClass>
</PropertyOPType>
<PropertyOPTypeData>
<Level>
1
</Level>
<..sub-tree for data structure description..>
</PropertyOPTypeData>
</PropertyParameter>
<PropertyParameter>
<PropertyOPType>
<OPTypeClass>
<Command ..attributes.. OPTypeRef="XType1">
</Command>
</OPTypeClass>
</PropertyOPType>
</PropertyParameter>
</PropertyClass>
</Property>
</FunctionClass>
</Function>
<Function>
<FunctionClass ..attributes..>
<Method>
<MethodClass ..attributes..>
<MethodParameter>
<MethodOPType>
<OPTypeClass>
<Command ..attributes.. OPTypeRef="XType3">
</Command>
</OPTypeClass>
</MethodOPType>
<MethodOPTypeData>
<MethodOPTypeData>
<Level>
0
</Level>
<..sub-tree for data structure description..>
</MethodOPTypeData>
</MethodOPTypeData>
</MethodParameter>
</MethodClass>
</Method>
</FunctionClass>
</Function>
</..several superstructures, repeatedly..>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list