SGMLXML.net A place for SGML and XML application developers.

March 11, 2005

Example of XSLT document() function to create a lookup table

Filed under: XSLT — cangione @ 1:56 pm




 This technique can be used to add metadata to incoming source documents.< ?xml:namespace prefix = o />

 Source:

<![CDATA[

<?xml version="1.0" encoding="UTF-8"?>

<mydoc>

            <title>Introduction</title>

            <title>Introduction2</title>

            <title>Bogus</title>

</mydoc>

]]>

 Stylesheet:

<![CDATA[

<?xml version="1.0" encoding="UTF-8"?>

<xsl:transform   version="1.0"

                        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

                        xmlns:book="books.uri"

                        exclude-result-prefixes="book">

            <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

<xsl:template match="/">

            <xsl:apply-templates/>

</xsl:template>

<xsl:template match="mydoc">

            <xsl:apply-templates/>

</xsl:template>           

<xsl:template match="title">

            <xsl:value-of select="document('')/*/book:category[@desc=current()]/@code"/>

</xsl:template>

<book:category code="1" desc="Introduction"/>

<book:category code="1" desc="Introduction2"/>

<book:category code="2" desc="Bogus"/> 

</xsl:transform>

]]>

 

 

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress