admin管理员组

文章数量:1122832

I have a working .xsl but I wanted to add a check to see if the current cell is in the first row and first cell:

    <xsl:for-each select="w:tr">
        <xsl:for-each select="w:tc[position()!=last()]">
            
            <!-- Check if first row and if is first column -->
            <xsl:if test="w:tr[position()=first()] and w:tc[position()=first()]">
            <xsl:text>\mcx</xsl:text> 
        </xsl:if>
        <!-- Check if is first row only -->
        <xsl:if test="w:tr[position()=first()] and w:tc[position()!=first()]">
            <xsl:text>\mc</xsl:text>
        </xsl:if>
    </xsl:for-each>
</xsl:for-each>


I am unable to apply the .xsl with these lines added. If I take them out, it works, so I know that my check isn't correct. Can someone help me with the wordML side. As I approaching this wrong?

Thanks,

Russ

I have a working .xsl but I wanted to add a check to see if the current cell is in the first row and first cell:

    <xsl:for-each select="w:tr">
        <xsl:for-each select="w:tc[position()!=last()]">
            
            <!-- Check if first row and if is first column -->
            <xsl:if test="w:tr[position()=first()] and w:tc[position()=first()]">
            <xsl:text>\mcx</xsl:text> 
        </xsl:if>
        <!-- Check if is first row only -->
        <xsl:if test="w:tr[position()=first()] and w:tc[position()!=first()]">
            <xsl:text>\mc</xsl:text>
        </xsl:if>
    </xsl:for-each>
</xsl:for-each>


I am unable to apply the .xsl with these lines added. If I take them out, it works, so I know that my check isn't correct. Can someone help me with the wordML side. As I approaching this wrong?

Thanks,

Russ

Share Improve this question asked Nov 22, 2024 at 21:30 Russell Urquhart CRussell Urquhart C 174 bronze badges 3
  • 1 Please provide a minimal reproducible example showing an example of the input, your current stylesheet and the expected output. – michael.hor257k Commented Nov 22, 2024 at 21:35
  • It is a very long .xsl, I'll try and see if I can minimize to something testable. I was really just hoping someone could tell me if the tabel and row WordML commands I was trying to use were correct? – Russell Urquhart C Commented Nov 22, 2024 at 23:09
  • 1 Oh, that part is easy: they are not. But in order to fix them we need to see the context. – michael.hor257k Commented Nov 23, 2024 at 1:46
Add a comment  | 

1 Answer 1

Reset to default 1

I am purely guessing you want to do something like:

<xsl:for-each select="w:tr">
    <xsl:variable name="is1stRow" select="position()=1" />
    <xsl:for-each select="w:tc">
        <xsl:choose>
            <xsl:when test="$is1stRow and position()=1">
                <!-- this is the first cell in the first row -->
                <xsl:text>\mcx</xsl:text> 
            </xsl:when>
            <xsl:when test="$is1stRow">
                <!-- this is another cell in the first row -->
                <xsl:text>\mc</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <!-- this is a cell in another row -->
                <!-- do something here? -->
            </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>
</xsl:for-each>

Side note:

There is no first() function in XSLT. XSLT in not an intuitive language. You cannot succeed by trial-and-error.

本文标签: