[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: XSLT stylistics query
You can use the XSLT current() function if you prefer this to using variables. (Some people prefer variables). You can also make do with a single variable: <xsl:for-each select="document($cfgschema)/ConfigSchema/RootSection"> <xsl:variable name="x" select="." /> <xsl:variable name="SectTypeDef" select="document($cfgschema)/ConfigSchema/SectionType[@Name=$x/@Type]"/> or <xsl:for-each select="document($cfgschema)/ConfigSchema/RootSection"> <xsl:variable name="SectTypeDef" select="document($cfgschema)/ConfigSchema/SectionType[@Name=current()/@Type] "/> I would actually tend to write this as: <xsl:for-each select="document($cfgschema)/ConfigSchema/RootSection"> <xsl:variable name="SectTypeDef" select="../SectionType[@Name=current()/@Type]"/> unless there are many SectionTypes, in which case I would use a key. XSLT coding questions are probably better discussed over on xsl-list at mulberrytech.com Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Simon Kissane [mailto:skissane@g...] > Sent: 08 February 2005 06:46 > To: xml-dev@l... > Subject: XSLT stylistics query > > Hi, > > When I write XSL stylesheets, I often find myself writing code like > the following sample: > > <xsl:template name="check-root-sections"> > <xsl:for-each select="document($cfgschema)/ConfigSchema/RootSection"> > <xsl:variable name="SectName" select="@Name" /> > <xsl:variable name="SectType" select="@Type" /> > <xsl:variable name="SectTypeDef" > select="document($cfgschema)/ConfigSchema/SectionType[@Name=$S ectType]" > /> > <xsl:variable name="SectInstance" > select="document($srcdoc)/Config/Section[@Name=$SectName]" /> > .... > > Notice that I declare these two variables, $SectName and $SectType. My > purpose in doing > so is because inside the [ ... ] operator, according to my > understanding, the context node changes to the node before the > operator. So, if I want to find something in my original context node, > before the [ ], I need to assign it to a variable first. (In fact, in > the above example, the two context nodes belong to entirely different > documents...) > > Is there a cleaner way of doing this? Some XPath syntax to enable me > to say "the context node previous to the current top of stack..."? If > there was such a syntax, my code would be a lot cleaner, since I > wouldn't need so many variable declarations. > > Cheers > Simon Kissane > > ----------------------------------------------------------------- > The xml-dev list is sponsored by XML.org <http://www.xml.org>, an > initiative of OASIS <http://www.oasis-open.org> > > The list archives are at http://lists.xml.org/archives/xml-dev/ > > To subscribe or unsubscribe from this list use the subscription > manager: <http://www.oasis-open.org/mlmanage/index.php> >
|
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
|