Subject: RE: [xsl] How to use the same expression in a match and a select test From: "Scott Trenda" <Scott.Trenda@xxxxxxxx> Date: Mon, 3 Dec 2007 09:41:42 -0600 |
Sascha, I've had to do something similar to this before; however, I'm limited to using XSLT 1.0. (Just wanted to reply with the pattern that worked for me, in case others need to do this in XSLT 1.0 and can't use entities within their documents.) What I did was created a stylesheet element like so: <some:matches> <some:match name="blockquote"/> <some:match name="center"/> <some:match name="hr"/> <some:match name="form"/> <some:match name="td"/> <some:match name="th"/> <!-- etc. --> </some:matches> <xsl:template match="*[name() = document('')/*/some:matches/*/name]"/> <xsl:for-each select="*[name() = document('')/*/some:matches/*/name]"/> If you have several places where the set is used within select attributes (not matches), you can, of course, select it into a variable: <xsl:variable name="names" select="document('')/*/some:matches/*/name]"/> and use that: <xsl:for-each select="*[name() = $names]"/> Either way, it definitely does increase your stylesheet readability, extensibility and maintainability. ~ Scott -----Original Message----- From: Sascha Mantscheff [mailto:922492@xxxxxx] Sent: Monday, December 03, 2007 7:21 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] How to use the same expression in a match and a select test I have a stylesheet with a template and a for-each statement. Both select their elements by an expression which differs only in one part from each other. The template is: <xsl:template match="*[not(self::blockquote|self::center|self::BODY| self::body|self::div|self::dl|self::dt|self::HEAD|self::head|self::HTML| self::img|self::h1|self::h2|self::h3|self::h4|self::h5|self::h6| self::hr|self::html|self::idx:*|self::form| self::mbp:*[not(self::mbp:nu)]|self::mmc:*|self::ol|self::p|self::table| self::td|self::th|self::tr| self::ul)][preceding-sibling::node()[1][name()=name(current()) and string-join(@*,'xx') = string-join(current()/@*,'xx')]]" /> The for-each select is: <xsl:for-each select="following-sibling::node()[1][not(self::blockquote| self::center|self::BODY|self::body|self::div|self::dl|self::dt| self::HEAD|self::head|self::HTML|self::img|self::h1|self::h2|self::h3| self::h4|self::h5|self::h6|self::hr|self::html|self::idx:*|self::form| self::mbp:*[not(self::mbp:nu)]|self::mmc:*|self::ol|self::p|self::table| self::td|self::th|self::tr|self::ul)] [name()=name(current()) and string-join(@*,'xx') = string-join(current()/@*,'xx')]"> How can I reduce the redundancy and use the same expression in both statements, like in this pseudo code: <xsl:template match="*[$NO_BLOCK_ELEMENTS][preceding-sibling::node()[1][name()=name(cu rrent()) and $SAME_ATTRIBUTES]]" /> <xsl:for-each select="following-sibling::node()[1][$NO_BLOCK_ELEMENTS] [name()=name(current()) and $SAME_ATTRIBUTES]">
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] How to use the same expre, Mukul Gandhi | Thread | [xsl] no closing tag on embed with , Jared Stein |
RE: [xsl] count(preceding-sibling ), Scott Trenda | Date | Re: [xsl] How to use the same expre, Mukul Gandhi |
Month |