Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xsl for-each

Status
Not open for further replies.

KevinDW

IS-IT--Management
Apr 11, 2012
2
BE
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">= </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]">

 
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)">
		[b]...do something[/b]
		<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:
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.
 
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







 
Hi Kevin,

"position" is an aatribut, so you need to address it as "[red]@[/red]position"
;-)

“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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top