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

Re: Tag libraries in XSLT / XQuery?

  • From: Evan Lenz <evan@evanlenz.net>
  • To: Erik Hennum <efhennum@gmail.com>
  • Date: Wed, 25 Aug 2010 17:05:13 -0700

Re:  Tag libraries in XSLT / XQuery?
Hi Erik,

I think for most cases, basic XSLT processing, using a modified identity 
transform, should do the trick. Then, you simply define the tags in the 
tag library using normal XSLT template rules, as done here:
https://code.google.com/p/rundmc/source/browse/trunk/view/tag-library.xsl

This is part of the code I wrote in a project to create a back-end 
framework for the MarkLogic Developer community.

Note that there are no pre-processors or other such acrobatics. Just a 
modified identity transform, with a (left-most-indented) template rule 
in the unnamed mode for each custom tag in the library.

For example, the source for the current home page's content (at 
http://developer.marklogic.com) looks like this:

<ml:page status="Published"
  xmlns:ml="http://developer.marklogic.com/site/internal"
  xmlns="http://www.w3.org/1999/xhtml">

  <h1>Learn, share, discuss</h1>

  <ml:tabbed-features>
    <ml:feature href="/features/eclipse.xml"/>
    <ml:feature href="/features/office-toolkits.xml"/>
    <ml:feature href="/features/xqdebug.xml"/>
  </ml:tabbed-features>

  <div class="announcement single">
    <p>Welcome to the MarkLogic Developer Community...</p>
    ...
  </div>

  <ml:recent-news-and-events suppress-more-links="yes"/>

  <ml:article-abstract heading="Check this out."
                       href="/learn/2009-07-search-api-walkthrough.xml"/>

</ml:page>


As you can see, it's a mixture of regular XHTML and custom tags (in the 
"ml" namespace). Apply page.xsl to this and you get the final XHTML 
result in the browser.

To see the custom tag implementations, just look at tag-library.xsl, 
e.g., <xsl:template match="tabbed-features">.

So, in my opinion, XSLT is already an excellent implementation language 
for custom tag libraries. (And with products that let you mix-and-match 
XSLT and XQuery, you can get the best of both worlds.)

If you wanted to extend it to support general XPath expressions (without 
using a pre-processor) you could use an eval() function, but I generally 
don't find the need to do that. Custom libraries are called "custom" for 
a reason. :-)

Evan

-- 
Evan Lenz
Lenz Consulting Group, Inc.
http://lenzconsulting.com
+1 (360) 297-0087



Erik Hennum wrote:
> Speculative XML Savants:
>
> I'm wondering whether a moral equivalent to JSP tag libraries [1] would
> be a useful addition to the XSLT / XQuery portfolio -- so that XML
> documents could use tags
>
> *  defined in an XSLT / XQuery module (instead of a Java class), and
> *  executed by an XSLT / XQuery processor (instead of a JSP container).
>
> The rationale for tag libraries (probably summarizing the familiar) is
> to establish a division of responsibility and collaboration between
>
> *  application developers who understand data access and manipulation, and
> *  page designers who understand visual layout and style.
>
> For an example, let's say an application developer creates a tag library
> with an query:people tag that queries attendee records by year and sorts
> the result list by first or last name.
>
> A page designer could then create an XHTML page with the query:people tag:
>
> <table class="attendees">
>   <tr><th>Last Name</th>
>     <th>First Name</th></tr>
> <query:people select-year="2010" sort-by="last-name">
>   <tr><td class="lname">{ $last-name  },</td>
>     <td class="fname">{ $first-name }</td></tr></query:people>
> </table>
>
> When supplied with the tag page and the tag library, a processor would
> generate an XHTML output page similar to the following:
>
> <table class="attendees">
>   <tr><th>Last Name</th>
>     <th>First Name</th></tr>
> <!-- query:people select-year="2010" sort-by="last-name" -->
>   <tr><td class="lname">Crawford,</td>
>     <td class="fname">Randy</td></tr>
>   <tr><td class="lname">Franklin,</td>
>     <td class="fname">Aretha</td></tr>
>   <tr><td class="lname">Green,</td>
>     <td class="fname">Albert</td></tr><!-- /query:people -->
> </table>
>
> Some potential scenarios for tags in XML processing environments:
>
> *  An XQuery tag library could provide views on an XML store for
>    integration and branding by HTML pages.
>
> *  An XSLT tag library could transform articles into content sequences
>    for layout as flows by XSL-FO book masters.
>
> XSLT Simplified Stylesheet Modules [2] already have several of the
> constructs needed for XML tag pages.  The legal XSLT statements include
> equivalents (such as xsl:for-each and xsl:if) for important core JSTL
> statements.  XSLT Attribute Value Templates [3] offer a parallel to the
> EL expression language.
>
> Simplified Stylesheet Modules would seem to need new constructs to:
>
> *  Import the XSLT / XQuery library modules that implement the tags.
> *  Execute value templates within element text (as with the $last-name
>    and $first-name expressions in the example above).
> *  Process tags as calls to library functions, passing the tag
>    attributes as function parameters and the tag content as a
>    callback (as with the attributes and content of the query:people tag).
>
> A XSLT or XQuery tag library module would seem to need new constructs to:
>
> *  Bind a tag name to its implementing function.
> *  Process callbacks zero or more times as appropriate.
>
> For experimentation, I put together a sketchy preprocessor [4] that
> converts an XHTML tag page and an XSLT tag module to intermediate XSLT
> files and then executes the intermediate XSLT files to produce an output
> XHTML document (supporting callbacks through Dimitre Novatchev's
> technique [5] for dynamic functions).
>
> This preprocessor has significant limitations with respect to callbacks.
> In particular, variables in scope at the definition of the callback
> fragment aren't in scope during processing of the callback fragment.
> One alternative might be to emit the tag implementation inline within
> the converted tag page.
>
> A really robust implementation of tag libraries may need native XSLT /
> XQuery anonymous functions.  (Having just noticed Dynamic Function
> Invocation [6] in the XPath 2.1 working draft, I'm wondering if that
> would help.)
>
> Anyway, that's the idea.  What do you think?  Wrongheaded?  Worth
> pursuing?
>
>
> Erik Hennum
>
>
> Acknowledgments:  The thought was triggered by a talk about virtual
> documents [7] by Vyacheslav Zholudev at the Balisage conference.
>
>
> [1] http://en.wikipedia.org/wiki/JSTL
> [2] http://www.w3.org/TR/xslt20/#simplified-stylesheet
> [3] http://www.w3.org/TR/xslt20/#dt-attribute-value-template
> [4] http://docs.google.com/leaf?id=0B_yrFnrTAZDGNGY3MjI2MTgtZGZjMS00ZDUwLTljNjgtNDg1NDdhNzY4NDE5&hl=en
>     CAVEAT:  only an experiment, may change completely or be abandoned
> [5] http://fxsl.sourceforge.net/
> [6] http://www.w3.org/TR/xpath-21/#id-function-invoke
> [7] http://www.balisage.net/Proceedings/vol5/html/Zholudev01/BalisageVol5-Zholudev01.html
>
> _______________________________________________________________________
>
> XML-DEV is a publicly archived, unmoderated list hosted by OASIS
> to support XML implementation and development. To minimize
> spam in the archives, you must subscribe before posting.
>
> [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
> Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
> subscribe: xml-dev-subscribe@lists.xml.org
> List archive: http://lists.xml.org/archives/xml-dev/
> List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
>




[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.