I have been given a book in xml to translate to xhtml. I have successfully met all the challenges but I have a big one still faceing me. I have to overide defaults in my css stylesheet. The best way to do that is to set the style attribute on the division. There will only be top margin, bottom margin, font color, and background color. This means that I have to build a string containing the desired CSS. I haven't had to use vaiables or parmeters to this point but I see no other way in this case.
I have made several attempts and I think I am close. The variable is getting built on the first match and I get the desired output. The scope changes (I think) and it works until I get another highlight box that needs to change.
The XML I am given looks like:
Code:
<HighlightBox topmargin="25px" bottom-margin="25px">
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut quis libero. Vivamus mollis. Aliquam eu eros. Nam varius lacus ut est. In hac habitasse platea dictumst. Suspendisse at velit in nulla semper fringilla. Suspendisse aliquam euismod tortor. Duis diam tortor, aliquam nec, aliquam ut, pharetra ac, purus. Nullam hendrerit. Etiam at metus quis lectus posuere venenatis. Quisque luctus scelerisque nunc. Fusce ultricies. Fusce vitae diam. Donec non urna quis lectus faucibus pretium. Nullam sed odio sit amet dolor tincidunt fringilla. Mauris eu tortor in ante commodo sodales. Morbi at arcu ut quam euismod elementum. Fusce libero leo, dictum vel, ultricies id, consectetuer a, nulla.
</p>
</HighlightBox>
The output would be
Code:
<div class="highlightbox" style="margin-top:25px; margin-bottom:25px">
<p>.....</p>
</div>
This is what I have come up with thus far:
Code:
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:node-set($styleString)/TempStyle/StyleTMargin,msxsl:node-set($styleString)/TempStyle/StyleBMargin)"/>
</xsl:attribute>
</div>
</xsl:template>