Back our Kickstarter Campaign going on Now
  1. #1

    css help with Print Campaign tool

    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:
    Code:
    				<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:
    Code:
    				<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:
    Attached Files Attached Files
    Last edited by Thete; April 18th, 2019 at 01:48.

  2. #2
    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.

  3. #3
    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!
    Last edited by Thete; April 19th, 2019 at 12:02.

  4. #4
    Quote Originally Posted by Thete View Post
    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.

  5. #5
    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.

    Capture.JPG

    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
    Last edited by Thete; April 22nd, 2019 at 07:33.

  6. #6
    Here is the printed result so far are attached, along with the custom font file to sit along side it.
    Attached Files Attached Files
    Last edited by Thete; April 22nd, 2019 at 04:56.

  7. #7
    I would recommend doing it in XSL.

    Code:
    <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

  8. #8
    Quote Originally Posted by ddavison View Post
    I would recommend doing it in XSL.

    Code:
    <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

    Code:
    <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. .

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Log in

Log in