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

Re: Humans are so clever

  • From: Tomos Hillman <yamahito@gmail.com>
  • To: "=?utf-8?Q?xml-dev=40lists.xml.org?=" <xml-dev@lists.xml.org>, "=?utf-8?Q?Costello=2C_Roger_L.?=" <costello@m...>
  • Date: Thu, 22 Aug 2019 10:37:51 +0100

Re:  Humans are so clever

You can use this:

<xsl:for-each select="key('books', 'hardcover')">...</xsl:for-each>

But you probably *should* use this:

<xsl:apply-templates select="key(....)"/>

Thanks,
Tom
On 9 Aug 2019, 12:23 +0100, Costello, Roger L. <costello@mitre.org>, wrote:

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

 



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.