PDA

View Full Version : css help with Print Campaign tool



Thete
April 18th, 2019, 01:46
Hi folks,
I'm noob-cludging (my term) the Campaign Print tool for an older non-core ruleset, I'm doing ok but am stumped by a style sheet issue. When printing to html the text description section of a category, it displays it as inline and ignores the <p></p> sections of the formatedtext. How can I get it to render each <p> section</p> to a new line?

Currently the text as:

ÿ You hit the target for normal damageÿÿÿ You hit the target for +2 damageûû Perform a manoeuvre for freeüü Your target may disengage from you for free
I am looking for it to display as:

ÿ You hit the target for normal damage
ÿÿÿ You hit the target for +2 damage
ûû Perform a manoeuvre for free
üü Your target may disengage from you for free

The section in the .db file:

<description type="formattedtext">
<p>ÿ You hit the target for normal damage</p>
<p>ÿÿÿ You hit the target for +2 damage</p>
<p>ûû Perform a manoeuvre for free</p>
<p>üü Your target may disengage from you for free</p>
</description>
The section in the print.xsl file that outputs it to html:

<div class="conservative"><xsl:value-of select="currentrecharge" />
<div class="ac_description"><xsl:value-of select="description" />
</div>
</div>

The outputted html file if anyone is willing to take a glance to help me out:

ddavison
April 18th, 2019, 02:39
I’m not at my Pc at the moment but look for apply-templates and templates that handle the <p> tags in the other example XSL files.

Thete
April 19th, 2019, 09:28
OK so its not a problem with my CSS, it's xsl stripping out the <p></p> tags?

**Edit**
Ah-hah, I needed to use <xsl:copy-of select="description" /> instead of <xsl:value-of select="description" /> to preserve the html within the description text field!

ddavison
April 19th, 2019, 14:14
OK so its not a problem with my CSS, it's xsl stripping out the <p></p> tags?

**Edit**
Ah-hah, I needed to use <xsl:copy-of select="description" /> instead of <xsl:value-of select="description" /> to preserve the html within the description text field!

+1 Good job. Sorry, I bounce back and forth between things so much that I missed that.

Thete
April 22nd, 2019, 04:45
Things are progressing. So now I've created a custom font to sit along side the printed html file in order to display the ruleset specific dice characters. I've even designed new font characters to display other aspects of the wfrpv3 symbols in order to not need to include images.

27134

However I have another hurdle (that also isn't fixable in css). Dice in WFRPv3 are colour coded. The two black squares in the image are actually two different characters that represent two different colored dice, written in the database file as codes, in this example: &#242 & &#241 .
I need to be able to color code the dice characters, so one of those, ò needs to be white to represent a white dice.

I guess I could do this one of two ways:

1: A javascript that applies the color white to every instance of the ò character in the html file's body text.
or
2: A xsl command that searches for &#242 in the text of an element and replaces it with: <span style="color:white;">&#242</span>


Any suggestions on how to do either of those as I'm not familiar with either xsl or javascript :)

Thete
April 22nd, 2019, 04:52
Here is the printed result so far are attached, along with the custom font file to sit along side it.

ddavison
April 22nd, 2019, 15:22
I would recommend doing it in XSL.



<xsl:if test="myelementname = &#242">
<span style="color:white;">&#242</span>
</xsl:if>
<xsl:if test="myelementname != &#242">
<span style="color:red;">&#241</span>
</xsl:if>


https://www.w3schools.com/xml/ref_xsl_el_if.asp

Thete
April 23rd, 2019, 01:51
I would recommend doing it in XSL.



<xsl:if test="myelementname = ò">
<span style="color:white;">ò</span>
</xsl:if>
<xsl:if test="myelementname != ò">
<span style="color:red;">ñ</span>
</xsl:if>


https://www.w3schools.com/xml/ref_xsl_el_if.asp

Thanks Dr. D, that helped point me forward. My issue is that unfortunately copy-of command, although it preserves the formating as I want, doesn't allow an opportunity to alter the element's content. So I'm trying the <xsl:copy> </xsl:copy> instead.
The closest I could seem to get is adding a search and replace template as described here: https://www.oreilly.com xslt cookbook example (https://www.oreilly.com/library/view/xslt-cookbook/0596003722/ch01s07.html)



<xsl:call-template name="search-and-replace">
<xsl:with-param name="input" select="conservative/description"/>
<xsl:with-param name="search-string" select="'ò'" />
<xsl:with-param name="replace-string" select="'<span style="color:white">&#242 </span>'"/>
</xsl:call-template>
</xsl:copy>

<xsl:template name="search-and-replace">
<xsl:param name="input"/>
<xsl:param name="search-string"/>
<xsl:param name="replace-string"/>
<xsl:choose>
<!-- See if the input contains the search string -->
<xsl:when test="$search-string and
contains($input,$search-string)">
<!-- If so, then concatenate the substring before the search
string to the replacement string and to the result of
recursively applying this template to the remaining substring.
-->
<xsl:value-of
select="substring-before($input,$search-string)"/>
<xsl:value-of select="$replace-string"/>
<xsl:call-template name="search-and-replace">
<xsl:with-param name="input"
select="substring-after($input,$search-string)"/>
<xsl:with-param name="search-string"
select="$search-string"/>
<xsl:with-param name="replace-string"
select="$replace-string"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- There are no more occurences of the search string so
just return the current input string -->
<xsl:value-of select="$input"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>




Which -almost- works except it a) seems to break xsl when I quote the html <span> code as what is to be injected and b) strips the HTML formatting anyways :-/
Unless someone can see what I'm doing wrong...am thinking I'll need to try investigating the javascript idea. :).