Actually you could make it as flexible or rigid as you want, but youre right,
this is a very flexible solution that would only require someone with basic
knowledge of XML or an editor that puts the data into a grid like format or ...
to be able to manage the links for the site relieving your self or any other
developers on staff to focus on creating more site features or faster
transformations or layout changes or ... From your statement you obvious see
the potential in all of this....
Extending your understanding of templates and the match attribute a bit will
help you see other ways to process your input data...
Take the same input XML >
<data>Please send comments to the <a href="web master">web master</a>for this
site</data>
and then change the value of the match attribute of the template you want to
match all <a> tags that contain an attribute "href" with a value of "web master"
to look like this...
<xsl:template match="a[@href = 'web master']">
<!-- enter what you want to output when this XPath test evaluates to true -->
</xsl:template>
Not to confuse matters too much but you seem like someone who obviously comes
from a development background so Im not to worried... by adding one more
attribute to the xsl:template element we can further qualify which template to
use when there are several possible matches to the XPath found in the underlying
template base... this attribute is "mode" and by setting and then using its
associated value as the value of the mode attribute of the calling element
(either xsl:apply-templates or xsl:call-template) you can then tell the
processor which specific template with the match value set to "a" to use... So,
for example:
<xsl:param name="mode" select="/output/@mode"/>
<!-- by using xsl:param you allow the processor to pass in the value of a named
parameter and reset its value to the passed in value. If you dont plan on
passing in the value from the command line, codebase, or development tool
interface then use xsl:variable instead -->
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$mode = 'print'">
<xsl:apply-templates select="a" mode="print"/>
</xsl:when>
<!-- add as many xsl:when elements as you want to properly qualify the possible
values of the mode variable (or whatever name you might use in your stylesheet)-->
<xsl:otherwise>
<xsl:apply-templates select="a" mode="web"/>
</xsl:otherwise>
</xsl:choose<
</xsl:template>
<xsl:template match="a" mode="web">
<a href="{document('href_values.xml')/links/href[@match_user =
$href]/@href_value}"><xsl:value-of select="."/></a>
<!-- the above is a shortcut to doing the same thing we did the first time
around. Using xsl:attribute allows you the luxury of setting the name of the
attribute dynamically e.g. <a><xsl:attribute
name="{$name_of_some_local_or_global_variable}"><xsl:value-of
select="."/></xsl:attribute></a> or adding additional attributes 1-N to the
element within its context, in this case the <a> element. If neither of these
is necessary then use the shorthand version above -->
</xsl:template>
<xsl:template match="a" mode="print">
<xsl:variable name="user" select="@href"/>
<xsl:variable name="user_values"
select="document('user_values.xml')/users/user[@match_user = $user]"/>
Please contact <xsl:value-of select="$user_values/@user_name"/> at <xsl:value-of
select="$user_values/@user_phone"/> during normal business hours.
</xsl:template>
Hopefully by adding this information to your knowledge base of how to get the
most out of template matching you will be able to see and subsequentally
implement a solution more specific to your needs that will implement the proper
seperation of Church(the XML data - structured data who's only concern is
delivering the correct information via the correct structure to allow proper
interpretation by whomever may be listening) and State(the XSLT stylesheet -
structured processing elements who's only concern is to properly interpret which
law applys to the current object(containing element) in context and then
properly invoking the process set forth by this law which could entail one or
many of the following:
- putting the object through a local transformation process which will decide if
a simple transformation can take place or if the object contains further
elements that need to be evaluated by any number of possible
jurisdictions/arresting agencys/state sponsored programs for further
interpretation and processing.
- releasing the entire object to the proper jurisdiction/arresting agency/state
sponsored program for further analysis before making any decisions as to what
kind of transformation process is necessary, if any, to ensure that when the
object has gone through all of the necessary steps it will look to the end user
exactly the way the law specified it should look and therefore can be stamped
"transformed" and sent back to society as a brand new entity structure/type. :)
- continue to evaluate every element of the object, stripping each of its
structure and restructuring it in a way that the specified agency feels is
correct as far as the condition the element was brought to the agency in and
subsequently evaluated to determine just what it is that the stripped down
object is really supposed to be according to the specification set forth by the
governing force that controls the ultimate destiny of every object, element,
attribute and value that it has been given by the "System" to transform
according to the laws set forth and then returned back to the "System"
completely transformed into the "type" of object the "System" felt you would
best be suited for and subsequently introduced into the an environment where its
"type" will be properly understood and accepted.
It's obviously getting late... But if you can't digress every once and a while
life gets boring... :D Have a good night!
Best of luck,
<M:D/>