INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

xsl for-each

xsl for-each

(OP)
I have the following XML code:

<n-grams-sorted analysis="N_GRAM_TOKEN2" range="Total Set" types="33459" tokens="50285">
    <n-gram position="1" frequency="387" probability="0.0077">x =</n-gram>
    <n-gram position="2" frequency="319" probability="0.00634">! =</n-gram>
    <n-gram position="3" frequency="295" probability="0.00587">= [i]</n-gram>
    <n-gram position="4" frequency="286" probability="0.00569">? =</n-gram>
    <n-gram position="5" frequency="221" probability="0.00439">love =</n-gram>
    <n-gram position="6" frequency="186" probability="0.0037">. =</n-gram>
    <n-gram position="7" frequency="182" probability="0.00362">:p =</n-gram>

....

<n-gram position="90" frequency="25" probability="0.0005">? :p</n-gram>


How do you get the first 30 with a <xsl:for-each> ?

<xsl:for-each select="//n-gram[@position &lt; $position]">

 

RE: xsl for-each

Hi KevinDW,

1.) Nice smilie in your code! lol

2.) This does not work this way. It seems the only way is to use a recursive template.
Found this snippet:

CODE

<xsl:template name="recurse_till_ten">
    <xsl:param name="num">1</xsl:param> <!-- param has initial value of 1 -->
    <xsl:if test="not($num = 10)">
        ...do something
        <xsl:call-template name="recurse_till_ten">
            <xsl:with-param name="num">
                <xsl:value-of select="$num + 1">
            </xsl:with-param>
        </xsl:call-template>
    </xsl:if>
</xsl:template>
Source: http://sourceware.org/ml/xsl-list/2000-08/msg01503.html

Adjust from 10 to 30 and put your processing code at the do something position.

Hope this helps.

Cheers,
MakeItSo

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

RE: xsl for-each

(OP)
Hey MakeItSo,

Your code helps me a lot.

But I have just one little question:

I want to select "position"
from

<n-gram position="1" frequency="387" probability="0.0077">x =</n-gram>

with

<xsl:value-of select="./position"/>

But it's not correct?
Do you know the solution for this one?

Kevin







 

RE: xsl for-each

Hi Kevin,

"position" is an aatribut, so you need to address it as "@position"
winky smile

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close