xsl-list
[Top] [All Lists]

RE: [xsl] Assigning serial numbers

2010-04-10 02:10:09
Try the below:

<xsl:template match="/">
       <table>
           
                <xsl:variable name="serial">
                <xsl:for-each select="//a/@href">
                <xsl:if test="not(for $x in //@id return
$x[$x=current()])">
                <xsl:copy-of select="ancestor::a[1]"/>
                </xsl:if>
                </xsl:for-each>
                </xsl:variable>
                
                <xsl:for-each select="$serial/a">
            <tr>
                <td><xsl:value-of select="position()"/></td>
                <td><xsl:value-of select="@href"/></td>
                        </tr>
                </xsl:for-each>
        </table>
</xsl:template>

<xsl:template match="text()"/>

Regards,
Ramesh

-----Original Message-----
From: Siddhi Thakkar [mailto:siddhi(_dot_)thakkar(_at_)aptaracorp(_dot_)com] 
Sent: Saturday, April 10, 2010 12:07 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Assigning serial numbers

Dear Experts,

I need to create an HTML table of dead links and assign serial numbers
to 
it. Here is what my input looks like:

<book>
    <para id="p1"> .....some text..... <a href="p5">.....</a> ...some 
text..... </para>
    <article id="p2"> ......some text..... <a href="p1">......</a> text2

</article>
    <section id="p3">.....some text....<a 
href="p9">.....</a>...........</section>
</book>

Since two of the href attribute values listed above (p5 and p9) have no 
corresponding id values, these are the dead links. Please note that I
have 
got the list of such links, I AM ONLY STUCK AT PROVIDING SERIAL NOS. 
Mentioned below is my XSL code:

<!--CODE START-->
<xsl:output method="html"/>
<xsl:template match="/">
       <table>
           <xsl:apply-templates/>
        </table>
</xsl:template>

<xsl:template match="//a">
        <xsl:for-each select="@href">
                <xsl:if test="not(for $x in //@id return
$x[$x=current()])">
                        <tr>
                                <td>
                                    <!-- This is where I would like to
write 
the code to assign serial number-->
                                </td>
                                <td>
                                        <xsl:value-of
select="current()"/>
                                </td>
                    </tr>
              </xsl:if>
        </xsl:for-each>
</xsl:template>

<xsl:template match="text()"/>
<!--CODE END-->

DESIRED OUTPUT:
<table>
    <tr>
        <td>1</td>
        <td>p5</td>
    </tr>
    <tr>
        <td>2</td>
        <td>p9</td>
    </tr>
</table>

Thanks much,
Siddhi 



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>