Hello again,
This is part two of the trouble I am having with xsl transformations, and is
a continuation of my previous post:
"trouble merging an XHTML and XML document into one"
The reason I wish to merge the two into one is actually so I can perform
another transformation on the new merged document.
The setup (assuming the previous merge worked):
I now have some raw xml in memory...
---------------------------------------------------------------------
<NewPage>
<html xml...>
<body>
Bruce
<br/>
<input id="btnDoSomething" type="button" value="Do Something"/>
</body>
</html>
<RenderingControl>
<ElementToBeChanged>
<Name>btnDoSomething</Name>
<RenderAs>Read-Only</RenderAs>
</ElementToBeChanged>
</RenderingControl>
</NewPage>
The xsl transformation I wish to perform on the raw XML...
---------------------------------------------------------------------
ReRender.xsl
---------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="RenderingControl">
<xsl:variable name="CurrentElement" select="Name"/>
<xsl:for-each select="html">
<xsl:choose>
<xsl:when test=".[@id=$CurrentElement]">
<xsl:variable name="RenderElementAs"><xsl:value-of
select="RenderingControl/ElementToBeChanged/{@id}/RenderAs"/></xsl:variable>
<xsl:choose>
<xsl:when test="button">
<xsl:if test="RenderElementAs='HIDDEN'">
<xsl:attribute name="visibility">hidden</xsl:attribute>
</xsl:if>
<xsl:if test="RenderElementAs='READONLY'">
<xsl:attribute name="read-only">true</xsl:attribute>
</xsl:if>
<xsl:if test="RenderElementAs='NORMAL'">
<xsl:attribute name="visibility">visible</xsl:attribute>
<xsl:attribute name="read-only">false</xsl:attribute>
</xsl:if>
</xsl:when>
<!-- other HTML elements here -->
<xsl:otherwise>
<!-- do nothing - leave the original HTML untouched -->
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$CurrentElement"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
What I am hoping to achieve is any form element in <HTML ...> tree that has
a corresponding entry in the <RenderingControl> tree will convert its
attributes to the new one (re-rendering essentially),
and any part of the html that doesn't correspond to a RenderingControl
should just be copied 'as is'.
The resulting HTML...
<html xml...>
<body>
Bruce
<br/>
<input id="btnDoSomething" READ-ONLY="Read-Only" type="button"
value="Do Something"/>
</body>
</html>
SaberBruce
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list