Question
· Jul 22, 2021

Dynamically updating XData XslFoXslt sections

I'm writing a ZEN PDF report that uses StyleCalls to modify/HiLight table cells.

Is it possible to use a ZenMethod to create the Xdata below? I need to modify the colors based on flags.

 

XData XslFoXslt
{
<xsl:template name="HighLight">
<xsl:param name="Value"/>
<xsl:if test="$Value = 0">
<xsl:attribute name='font-weight'>normal</xsl:attribute>
<xsl:attribute name='background-color'>#ffffff</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 1">
<xsl:attribute name='font-weight'>normal</xsl:attribute>
<xsl:attribute name='background-color'>#dfdfdf</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 2">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#ffffff</xsl:attribute>
<xsl:attribute name='color'>#d70825</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 3">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#dfdfdf</xsl:attribute>
<xsl:attribute name='color'>#d70825</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 4">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#ffffff</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 5">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#dfdfdf</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 6">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#71af2d</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 7">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#71af2d</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 8">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#fbb800</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 9">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#fbb800</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 10">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#ef7917</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 11">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#ef7917</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if> <xsl:if test="$Value = 12">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#b90064</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 13">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#b90064</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if> <xsl:if test="$Value = 14">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#472784</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 15">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#472784</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if> <xsl:if test="$Value = 16">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#05bfc4</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 17">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#05bfc4</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 18">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#86888c</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 19">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#86888c</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 20">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#50535a</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 21">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#50535a</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 22">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#11316e</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 23">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#11316e</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 24">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#d70825</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 25">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#d70825</xsl:attribute>
<xsl:attribute name='color'>#000000</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 30">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#ffffff</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 31">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#dfdfdf</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 32">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='padding-left'>10px</xsl:attribute>
<xsl:attribute name='background-color'>#ffffff</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 33">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='padding-left'>10px</xsl:attribute>
<xsl:attribute name='background-color'>#dfdfdf</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 34">
<xsl:attribute name='font-weight'>normal</xsl:attribute>
<xsl:attribute name='padding-left'>20px</xsl:attribute>
<xsl:attribute name='background-color'>#ffffff</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 35">
<xsl:attribute name='font-weight'>normal</xsl:attribute>
<xsl:attribute name='padding-left'>20px</xsl:attribute>
<xsl:attribute name='background-color'>#dfdfdf</xsl:attribute>
</xsl:if> <xsl:if test="$Value = 36">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#ffffff</xsl:attribute>
<xsl:attribute name='color'>#71af2d</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 37">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#dfdfdf</xsl:attribute>
<xsl:attribute name='color'>#71af2d</xsl:attribute>
</xsl:if> <xsl:if test="$Value = 38">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#ffffff</xsl:attribute>
<xsl:attribute name='color'>#d70825</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 39">
<xsl:attribute name='font-weight'>bold</xsl:attribute>
<xsl:attribute name='background-color'>#dfdfdf</xsl:attribute>
<xsl:attribute name='color'>#d70825</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 40">
<xsl:attribute name='font-weight'>normal</xsl:attribute>
<xsl:attribute name='background-color'>#ffffff</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 41">
<xsl:attribute name='font-weight'>normal</xsl:attribute>
<xsl:attribute name='background-color'>#fefefe</xsl:attribute>
</xsl:if>
<xsl:if test="$Value = 99">
<xsl:attribute name='background-color'>#ffffff</xsl:attribute>
</xsl:if> </xsl:template>
}

Discussion (1)1
Log in or sign up to continue

Attribute/Element references can be used within the XData, and thereby be controlled by whatever querying you are doing or via a CALL method

XData XslFoXslt
{
<xsl:template name="RatingR" >
<xsl:param name="value"/>
<xsl:if test='$value="R"'>
<xsl:attribute name='color'><xsl:value-of select='/MyReport/colorvalue1'/></xsl:attribute>
<xsl:attribute name='font-weight'>bold</xsl:attribute>
</xsl:if>
</xsl:template>
}

Where my data looks like this

<report xmlns="http://www.intersystems.com/zen/report/definition"
 name="MyReport" sql="select ID,Title, Category->CategoryName as Category, Rating, Length From Cinema.Film">
 <element name="colorvalue1" expression='"red"' />
<group name="Film">
<attribute name="Title" field="Title"/>
<attribute name="Category" field="Category"/>
<attribute name="Rating" field="Rating"/>
<attribute name="Length" field="Length"/>
<attribute name='User' expression='..PrintedBy'/> </group> </report>

OR

I could have a call method used

<report xmlns="http://www.intersystems.com/zen/report/definition"
 name="MyReport" sql="select ID,Title, Category->CategoryName as Category, Rating, Length From Cinema.Film"> <call method="GetColorDets"/>
<group name="Film">
<attribute name="Title" field="Title"/>
<attribute name="Category" field="Category"/>
<attribute name="Rating" field="Rating"/>
<attribute name="Length" field="Length"/>
<attribute name='User' expression='..PrintedBy'/> </group> </report>

Method GetColorDets(ByRef pParms) As %GlobalCharacterStream
{
set stream=##class(%GlobalCharacterStream).%New()
do stream.Write("<colorvalue1>")
set rec="red"
do stream.Write(rec)
do stream.Write("</colorvalue1>") quit stream
}