I have a need to dynamically determine the name of an attribute-set. I'm restricted to using XSLT 1.0 and we're currently using Xalan 2.7.1 for Java in both a Windows XP environment as well as an AIX environment.
Some history... I'm creating a stylesheet template that can be included in other developer's stylesheets that will generate "Link" tags for them. The system that I'm constrained to use is a custom portal application that has a content XML language that it uses to render HTML. It's a long story. Basically, a Link tag renders an HTML Anchor tag in the end. The DTD for the Link tag is as follows:
Code:
<!ELEMENT Link (#PCDATA | Image | Bold | Italic | Underline | LineBreak | Sup | MouseOverText)*>
<!ATTLIST Link
copy CDATA #IMPLIED
url CDATA #IMPLIED
target CDATA #IMPLIED
proxy (false | true) #IMPLIED
class CDATA #IMPLIED
onmouseover CDATA #IMPLIED
onmouseout CDATA #IMPLIED
onclick CDATA #IMPLIED
serviceid CDATA #IMPLIED
serviceparams CDATA #IMPLIED
componentid CDATA #IMPLIED
params CDATA #IMPLIED
contentID CDATA #IMPLIED
views CDATA #IMPLIED
groups CDATA #IMPLIED
rule CDATA #IMPLIED
ruledata CDATA #IMPLIED
ruleaction (include | exclude) #IMPLIED
title CDATA #IMPLIED
type (doc | secure-doc | anchor | external | internal) "internal"
>
I have to have a template to generate the Link tags because the template must evaluate the value of an XML node at runtime to determine the value of one of the attributes on the Link tag. Here is what I have so far.
Included Stylesheet
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="simulatedUser" select="/Message/MessageControlArea/transactionOriginLoggedInUserId"/>
<xsl:template name="SimulateLink">
<xsl:param name="realServiceid"/>
<xsl:param name="content"/>
<xsl:param name="attrSetName"/>
<xsl:element name="Link" use-attribute-sets="linkAttrSet">
<xsl:choose>
<xsl:when test="$simulatedUser = 'N/A' ">
<!-- ********** Not simulating -->
<xsl:attribute name="serviceid"><xsl:value-of select="$realServiceid"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<!-- ********** Simulating -->
<xsl:attribute name="serviceid">LFGSimulateUserService</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:copy-of select="$content"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
EXAMPLE:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:attribute-set name="linkAttrSet">
<xsl:attribute name="copy"><xsl:value-of select="current()//ProducerID"/></xsl:attribute>
<xsl:attribute name="serviceparams">ProducerID=<xsl:value-of select="current()//ProducerID"/>&CompanyCode=<xsl:value-of select="current()//CompanyCode"/></xsl:attribute>
<xsl:attribute name="ServiceID">LFGPOD</xsl:attribute>
<xsl:attribute name="ServiceInterface">GetPODProducerDetail</xsl:attribute>
</xsl:attribute-set>
<xsl:variable name='hubServiceId'>MyRealServiceId</xsl:variable>
<xsl:variable name="simulatedUser" select="/Message/MessageControlArea/transactionOriginLoggedInUserId"/>
<!-- Output Main Entry Point -->
<xsl:template match="/">
<WebPage>
<PrinterFriendly visible="true"/>
<Body>
<xsl:apply-templates select="/Message/Output"/>
</Body>
</WebPage>
</xsl:template>
<xsl:template match="Output">
<Form name="podEntryForm" method="post" action="">
<xsl:call-template name="SimulateForm">
<xsl:with-param name="realServiceid" select="$hubServiceId"/>
</xsl:call-template>
<table cellspacing="0" cellpadding="3" width="100%">
<xsl:for-each select="PODEntry[not(ProducerMessage)]">
<xsl:call-template name="PODEntry"/>
</xsl:for-each>
</table>
</Form>
</xsl:template>
<xsl:template name="PODEntry">
<tr>
<td align="left">
<xsl:call-template name="SimulateLink">
<xsl:with-param name="realServiceid" select="$hubServiceId"/>
<xsl:with-param name="content"/>
<xsl:with-param name="attrSetName">linkAttrSet</xsl:with-param>
</xsl:call-template>
<!--<Link>
<xsl:attribute name="copy"><xsl:value-of select="ProducerID"/></xsl:attribute>
<xsl:attribute name="serviceid"><xsl:value-of select="$hubServiceId"/></xsl:attribute>
<xsl:attribute name="serviceparams">ServiceID=LFGPOD&ServiceInterface=GetPODProducerDetail&ProducerID=<xsl:value-of select="ProducerID"/>&CompanyCode=<xsl:value-of select="CompanyCode"/></xsl:attribute>
</Link>-->
</td>
</tr>
</xsl:template>
<xsl:template name="SimulateForm">
<xsl:param name="realServiceid"/>
<xsl:choose>
<xsl:when test="$simulatedUser = 'N/A' ">
<!-- ********** Not simulating -->
<xsl:attribute name="serviceid"><xsl:value-of select="$realServiceid"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<!-- ********** Simulating -->
<xsl:attribute name="serviceid">LFGSimulateUserService</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="SimulateLink">
<xsl:param name="realServiceid"/>
<xsl:param name="content"/>
<xsl:param name="attrSetName"/>
<!--<xsl:element name="Link" use-attribute-sets="{$attrSetName}">-->
<xsl:element name="Link" use-attribute-sets="linkAttrSet">
<xsl:choose>
<xsl:when test="$simulatedUser = 'N/A' ">
<!-- ********** Not simulating -->
<xsl:attribute name="serviceid"><xsl:value-of select="$realServiceid"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<!-- ********** Simulating -->
<xsl:attribute name="serviceid">LFGSimulateUserService</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:copy-of select="$content"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
SAMPLE XML:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Message>
<Input>
<LFGApplicationID>server1</LFGApplicationID>
<LFGServiceID>LocalServiceId</LFGServiceID>
<LFGUserSessionID>AF88AEDE5B06A7F9B7701C847B7D7A32</LFGUserSessionID>
<LFGView>aView</LFGView>
<ServiceID>POD</ServiceID>
<ServiceInterface>GetPODEntryList</ServiceInterface>
</Input>
<MessageControlArea>
<interface>GetPODEntryList</interface>
<messageDateTime/>
<messageId>1b08a109:1227ee2e104:-7fdc</messageId>
<serviceName>LFGPOD</serviceName>
<transactionOriginSourceCode>Hub</transactionOriginSourceCode>
<transactionOriginUserId>testPOD</transactionOriginUserId>
<!--
<transactionOriginLoggedInUserId>N/A</transactionOriginLoggedInUserId>
-->
<transactionOriginLoggedInUserId>Mark</transactionOriginLoggedInUserId>
<transactionOriginSourcePassword>
<encryptionTypeCode>None</encryptionTypeCode>
<password>None</password>
</transactionOriginSourcePassword>
<transactionOriginUserPassword>
<encryptionTypeCode>hub</encryptionTypeCode>
<password>7c6a180b36896a0a8c02787eeafb0e4c</password>
</transactionOriginUserPassword>
<transactionOriginLoggedInUserPassword>
<encryptionTypeCode>N/A</encryptionTypeCode>
<password>N/A</password>
</transactionOriginLoggedInUserPassword>
<transactionId>1b08a109:1227ee2e104:-7fdb</transactionId>
</MessageControlArea>
<Output>
<PODEntry>
<ProducerID>9990352</ProducerID>
<ProducerMessage>Payment on Demand only allows one transaction per day.</ProducerMessage>
<CompanyCode>MAB</CompanyCode>
</PODEntry>
<PODEntry>
<ProducerID>9995859</ProducerID>
<ProducerMessage>Payment on Demand only allows one transaction per day.</ProducerMessage>
<CompanyCode>MAB</CompanyCode>
</PODEntry>
<PODEntry>
<ProducerID>9990002531</ProducerID>
<ProducerMessage>Payment on Demand only allows one transaction per day.</ProducerMessage>
<CompanyCode>MAB</CompanyCode>
</PODEntry>
<PODEntry>
<ProducerID>9990014716</ProducerID>
<MinAvailable>500</MinAvailable>
<RequestAmt>0</RequestAmt>
<CompanyCode>MAB</CompanyCode>
<AvailableAmt>250000</AvailableAmt>
<MaxAvailable>250000</MaxAvailable>
</PODEntry>
<PODEntry>
<ProducerID>0649720000</ProducerID>
<MinAvailable>0</MinAvailable>
<ProducerMessage>Available Amount Below Minimum</ProducerMessage>
<CompanyCode>MAB</CompanyCode>
<AvailableAmt>0</AvailableAmt>
<MaxAvailable>0</MaxAvailable>
</PODEntry>
</Output>
</Message>
What I'm trying to accomplish is to allow developers to create their own attribute-sets and pass the attribute-set name into the SimulateLink template and have the template generate Link tags using the attribute set the developer identified. The template works fine if I hardcode the name of the attribute-set in the use-attribute-sets attribute of the xsl:element tag. If I attempt to use an attribute value template, it doesn't expand the name.
Is there any way that I can provide a dynamic set of attributes to a template?
Thanks,
Mark