Forum Moderators: open
Here is the problem at a high level. Based upon an XML tag I must create an XHTML div. This div has a class with default styling but the user wants to be able to alter this styling but has only a limited knowledge of CSS. The only attributes she would alter is text color, background color, border color, top margin, and bottom margin.
The logic would be something like
If attributes are listed
for each attribute
if style attribute for the div exists
append appropriate CSS property and value to the style attribute
else
create a style attribute for the div with property and value
<xsl:if test="@Background">
<xsl:choose>
<xsl:when test="@style">
<xsl:value-of select="concat(@style,'background-color=',@Background,';')"/>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="style">
<xsl:value-of select="concat('background-color=',@Background,';')"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test="@Border">
<xsl:choose>
<xsl:when test="@style">
<xsl:value-of select="concat(@style,'border-color=',@Border,';')"/>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="style">
<xsl:value-of select="concat('border-color=',@Border,';')"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test="@Font">
<xsl:choose>
<xsl:when test="@style">
<xsl:value-of select="concat(@style,'color=',@Font,';')"/>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="style">
<xsl:value-of select="concat('color=',@Font,';')"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
A little more current thinking say that I should check the style first and nest the if inside but it occured to me that if I did that the attribute is not yet set so the appending to it would be a problem throug the remaining if statements.
/*****************************************************/
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns="http://www.w3.org/1999/xhtml"
>
<xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="HighlightBox">
<xsl:variable name="styleString">
<xsl:element name="TempStyle">
<xsl:for-each select="@*">
<xsl:element name="StyleTMargin">
<xsl:if test="local-name()='topmargin'">
<xsl:value-of
select="concat('margin-top:',.,';')"/>
</xsl:if>
</xsl:element>
<xsl:element name="StyleBMargin">
<xsl:if test="local-name()='bottom-margin'">
<xsl:value-of
select="concat('margin-bottom:',.,';')"/>
</xsl:if>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:variable>
<div>
<xsl:attribute name="style">
<xsl:value-of
select="concat(msxsl:nod-set($styleString)/TempStyle/StyleTMargin,msxsl:node-set($styleString)/TempStyle/StyleBMargin)"/>
</xsl:attribute>
</div>
</xsl:template>
</xsl:stylesheet>
/*******************************************************/
The problem is that I cant use the node-set function. I get the folowing error
/*******************************************************/
System.Xml.Xsl.XslTransformException was unhandled by user code
Message="Cannot find the script or external object that implements prefix 'urn:schemas-microsoft-com:xslt'."
Source="System.Data.SqlXml"
LineNumber=0
LinePosition=0
StackTrace:
at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
at System.Xml.Xsl.CompiledQuery.Query.<xsl:template match="HighlightBox">(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current, Double {urn:schemas-microsoft-com:xslt-debug}position, Double {urn:schemas-microsoft-com:xslt-debug}last, IList`1 {urn:schemas-microsoft-com:xslt-debug}namespaces) in C:\Users\crussell\Documents\Visual Studio 2005\WebSites\JanetReedPublications\MultiAtt.xsl:line 32
at System.Xml.Xsl.CompiledQuery.Query.<xsl:apply-templates>(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator , Double , Double )
at System.Xml.Xsl.CompiledQuery.Query.<xsl:apply-templates>(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator , Double , Double )
at System.Xml.Xsl.CompiledQuery.Query.<xsl:apply-templates>(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator , Double , Double )
at System.Xml.Xsl.CompiledQuery.Query.<xsl:apply-templates>(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator , Double , Double )
at System.Xml.Xsl.CompiledQuery.Query.<xsl:apply-templates>(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator , Double , Double )
at System.Xml.Xsl.CompiledQuery.Query.<xsl:apply-templates>(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator , Double , Double )
at System.Xml.Xsl.CompiledQuery.Query.Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at System.Xml.Xsl.CompiledQuery.Query.Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
at System.Xml.Xsl.XmlILCommand.Execute(XmlReader contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
at System.Xml.Xsl.XslCompiledTransform.Transform(XmlReader input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)
at Microsoft.Xsl.XslPlugin.Execute(String xml, Stream output, XmlOutputMethod& outputMethod)
/*****************************************
I feel sure that I am very close but not there yet