You can use this:
<xsl:for-each select="key('books', 'hardcover')">...</xsl:for-each>
Hi Folks,
Here are two examples of human ingenuity overcoming limitations.
No Block-Comment in Windows Batch (.bat) Files
The Windows batch command language provides “rem” (remark) to comment out a single line. For example, here I have commented out the first two lines of a batch file:
rem Command 1
rem Command 2
Command 3
When the batch file is run, Command 3 will be executed.
Suppose the batch file is large and you want to comment out a large section of the file. The Windows batch command language does not provide a block-comment syntax. You could prepend “rem” to every line (and then later remove them when you want to uncomment the lines) but that is tedious. So, some clever person came up with a workaround: The Windows batch command language provides a “goto” statement so use that to avoid executing a block of commands (thus effectively implementing a block comment). For example, here I avoid running Command 1 and Command 2 by using a goto statement:
goto :next
Command 1
Command 2
:next
Command 3
That is so ingenious!
No Composite Keys in XSLT
The XSLT language allows you to improve the performance of your XSLT program by using something called “keys”. Here is an example of declaring an XSLT key:
<xsl:key name="books" match="Book" use="binding" />
That instructs the XSLT processor to create a super-fast lookup table of Books so that the set of Books with a certain binding (hardcover or softcover) can be quickly retrieved.
Rather than using this in your XSLT program:
<xsl:for-each select="//Book[binding eq 'hardcover']">...</xsl:for-each>
You can use this:
<xsl:for-each select="key('books', 'hardcover')">...</xsl:for-each>
The latter can be much, much faster than the former.
Suppose you want to find Books using a combination of binding and author. That requires a composite key. XSLT does not support composite keys. So, some clever person came up with a workaround: concatenate the desired keys, like this:
<xsl:key name="books" match="Book" use="concat(binding, author)" />
If you want all the hardcover books by Tom Clancy, you can do this:
<xsl:for-each select="key('books', concat('hardcover', 'Tom Clancy'))">...</xsl:for-each>
That is so ingenious!
------------------------------------------------
Of course the above two examples are small things. But small things are used to build big things, so discounting small things would be a mistake.
What human ingenuity have you seen recently in the XML domain?
/Roger