Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 26th, 2005, 07:31 AM
Registered User
 
Join Date: Oct 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to bluetorch
Default i need to ....

i need to get a number from an elements attribute and use that number to set x <td></td> tags

Code:
<table:table-row table:style-name="ro1">
                <table:table-cell/>
                <table:table-cell table:value-type="string">
                    <text:p>B</text:p>
                </table:table-cell>
                <table:table-cell table:value-type="string">
                    <text:p>C</text:p>
                </table:table-cell>
                <table:table-cell/>
                <table:table-cell table:value-type="string">
                    <text:p>E</text:p>
                </table:table-cell>
            </table:table-row>
            <table:table-row table:style-name="ro1">
                <table:table-cell/>
                <table:table-cell table:value-type="string">
                    <text:p>B</text:p>
                </table:table-cell>
                <table:table-cell table:value-type="string">
                    <text:p>C</text:p>
                </table:table-cell>
                <table:table-cell table:number-columns-repeated="2"/>
            </table:table-row>
on the end you see <table:table-cell table:number-columns-repeated="2"/>
i need to use that 2 to let my xsl put two pairs of td tags like i said earlier

any ideas ?

 
Old October 26th, 2005, 09:56 AM
Registered User
 
Join Date: Oct 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to bluetorch
Default

im a little closer but still errors

Code:
<xsl:template match="table:table-cell">

        <xsl:if test="@text:p">
            <td><xsl:value-of select="text:p"/></td>
        </xsl:if>


                        <xsl:if test="@table:number-columns-repeated">

                    <xsl:call-template name="emptyColumns">
                            <xsl:with-param name="count" select="@table:number-columns-repeated" />
                    </xsl:call-template>

            </xsl:if>

    </xsl:template>


   <xsl:template name="emptyColumns">
   <xsl:param name="count" />
   #xa0;
   <xsl:if test="$count>0">
        <xsl:call-template name="emptyColumns">

            <xsl:with-param name="count" select="($count)-1" />
              <td/>
        </xsl:call-template>
   </xsl:if>


</xsl:template>
he gives an error that the td tags are not expected ... replacing them with <td/> doesnt work..

 
Old October 27th, 2005, 03:19 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In 2.0, do

<xsl:for-each select="1 to $n"><td/></xsl:for-each>

In 1.0, do

<xsl:template name="multi-td">
  <xsl:param name="n"/>
  <xsl:if test="$n > 0">
    <td/>
    <xsl:call-template name="multi-td">
      <xsl:with-param name="n" select="$n - 1"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

then:

<xsl:call-template name="multi-td">
  <xsl:with-param name="n" select="5"/>
</xsl:call-template>

Your mistake was putting a <td/> element as a child of call-template. The only thing allowed here is <xsl:with-param>.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 27th, 2005, 08:49 AM
Registered User
 
Join Date: Oct 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to bluetorch
Default

thx alot, it works, this will multiply my grade for this test at skool :]










Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.