Formatting dotted line inside a table using XSLT

2019-09-03 16:37发布

问题:

I am converting XML file using XSL Transformation in a Microsoft Word file.

I created this table:

You can see that this is an index alphabetical in two column.

The first column contains the city name;

The second column contains ......... (serves only for layout);

The third column contains number.

You can see for example:

ACCIAROLI.................... (a lot of blank space)|.............|2665.3 - 2666.5

In this case I would:

ACCIAROLI......................................................|.............|2665.3 - 2666.5

I would that dotted line in the first column, arrive until the end of first column, in order improved table formatting.

This is my XSLT 1.0:

<div>
    <table style="layout:fixed; font-size:9pt; border-style:none; border-collapse:collapse; vertical-align:top; width:100%; font-family:Univers Condensed;" border="none" cellspacing="0" cellpadding="0">
        <xsl:for-each select="//ITA_LIGHT_NUMBER[count(. | key('k', following-sibling::VICINITY | following-sibling::ITA_LIGHT_NAME[not(../VICINITY)])[1]) = 1]">
        <xsl:sort select="following-sibling::VICINITY | following-sibling::ITA_LIGHT_NAME[not(../preceding-sibling::VICINITY)]"/>
        <xsl:variable name="pos" select="position()"/>
        <xsl:variable name="passo" select="15"/>
        <xsl:variable name="posto" select="following-sibling::VICINITY"/>
            <xsl:if test="position() &lt; $passo">
                <tr>
                    <td>    // First Column
                        <span style="text-transform:uppercase;">
                            <xsl:choose>
                                <xsl:when test="not(following-sibling::VICINITY)">
                                   <xsl:value-of select="following-sibling::ITA_LIGHT_NAME"/>
                                   <xsl:text>....................</xsl:text>  //I would that This dotted line arrive at the end of column                                          
                                   <br/>
                                </xsl:when>
                                <xsl:otherwise>
                                   <xsl:if test="following-sibling::VICINITY != preceding::VICINITY[1] or not(preceding::VICINITY[1])">
                                        <xsl:value-of select="following-sibling::VICINITY"/>
                                        <xsl:text>....................</xsl:text>
                                        <br/>
                                   </xsl:if>
                                </xsl:otherwise>
                            </xsl:choose>
                        </span> 
                    </td>
                    <td style="width:2.00cm;">  //Second column
                        <span>................................</span>
                    </td>
                    <td>     //third column
                        <xsl:choose>
                            <xsl:when test="not(following-sibling::VICINITY)">
                               <xsl:value-of select="."/>
                               <br/>
                            </xsl:when>
                            <xsl:otherwise>
                               <xsl:if test="following-sibling::VICINITY != preceding::VICINITY[1] or not(preceding::VICINITY[1])">
                                    <xsl:value-of select="(//ITA_LIGHT_NUMBER[following-sibling::VICINITY = $posto])[1]"/>
                                            <xsl:if test="(//ITA_LIGHT_NUMBER[following-sibling::VICINITY = $posto])[1] != (//ITA_LIGHT_NUMBER[following-sibling::VICINITY = $posto])[last()]">
                                             <xsl:text> - </xsl:text>
                                             <xsl:value-of select="(//ITA_LIGHT_NUMBER[following-sibling::VICINITY = $posto])[last()]"/>
                                            </xsl:if>
                                            <br/>
                                           </xsl:if>
                            </xsl:otherwise>
                        </xsl:choose>
                    </td>
                </tr>
            </xsl:if>
        </xsl:for-each>
    </table>
</div>

Now I am reading from Enter Css File , and connect xslt to external css and I try to: (About First Column)

<xsl:when test="not(following-sibling::VICINITY)">
    <xsl:value-of select="following-sibling::ITA_LIGHT_NAME"/>
       <ul class="leaders.css">
           <link rel="stylesheet" type="text/css" href="leaders.css" />
                <li><span><xsl:text>....................</xsl:text></span></li>                                
       </ul>
       <br/>
</xsl:when>

Furthermore, i create this css file leader.css, it contains:

ul.leaders li { clear: both; }

ul.leaders li span:first-child {
    float: left;
    padding: 0 .4em 0 0;
    margin: 0;
}
ul.leaders li span + span {
    float: right;
    padding: 0 0 0 .4em;
    margin: 0;
}

ul.leaders li:after {
    content: "";
    display: block;
    overflow: hidden;
    height: 1em;
    border-bottom: 1px dotted;
}

Is it a possible solution?

回答1:

The question is a question not for XSL but for CSS. You can do that in many ways in CSS, see this:

http://www.w3.org/Style/Examples/007/leaders.en.html