xml - Selecting specific entries in a for-each loop? -


i have following xsl script:

<xsl:for-each select="$assignhistory/assignmenthistory/*[name()=$week]/studentitems/item">     student (or assistant): <xsl:value-of select="name"/><br /> </xsl:for-each> 

the actual xml studentitems have varied number of items in it. either:

1 7 14 21 

if there 7, want show list content this:

1 2 / 3 4 / 5 6 / 7 

if there 14:

1 2 / 3 4 / 5 6 / 7 8 9 / 10 11 / 12 13 / 14 

finally, if there 21:

1 2 / 3 4 / 5 6 / 7 8 9 / 10 11 / 12 13 / 14 15 16 / 17 18 / 19 20 / 21 

at moment getting varied "list" of names (understandably) can above? example xml content:

    <studentitems>         <item>             <name counsel="10">matthew 1</name>             <type>bible reading (main)</type>         </item>         <item>             <name counsel="44">john 2</name>             <type>#1 student (main)</type>         </item>         <item>             <name>robert 3</name>             <type>assistant</type>         </item>         <item>             <name counsel="38">rachel 4</name>             <type>#2 student (main)</type>         </item>         <item>             <name>aimie 5</name>             <type>assistant</type>         </item>         <item>             <name counsel="48">julie 6</name>             <type>#3 student (main)</type>         </item>         <item>             <name>diana 7</name>             <type>assistant</type>         </item>         <item>             <name counsel="5">gordon 8</name>             <type>bible reading (aux)</type>         </item>         <item>             <name counsel="39">sadie 9</name>             <type>#1 student (aux)</type>         </item>         <item>             <name>bethany 1</name>             <type>assistant</type>         </item>         <item>             <name counsel="38">zoe 2</name>             <type>#2 student (aux)</type>         </item>         <item>             <name>angela 3</name>             <type>assistant</type>         </item>         <item>             <name counsel="37">mary 4</name>             <type>#3 student (aux)</type>         </item>         <item>             <name>kate 5</name>             <type>assistant</type>         </item>     </studentitems> 

so mentioned number, referring item/name in list. thank assistance.

i suggest instead of:

<xsl:for-each select="$assignhistory/assignmenthistory/*[name()=$week]/studentitems/item">     student (or assistant): <xsl:value-of select="name"/><br /> </xsl:for-each> 

you do:

<xsl:apply-templates select="$assignhistory/assignmenthistory/*[name()=$week]/studentitems"/> 

then add these templates:

<xsl:template match="studentitems">     <xsl:apply-templates select="item[not((position() - 1) mod 7) or ((position() - 1) mod 7) mod 2] "/> </xsl:template>  <xsl:template match="item">     <xsl:value-of select="name"/>     <xsl:if test="(position() - 1) mod 4">         <xsl:apply-templates select="following-sibling::item[1]" mode="follower"/>     </xsl:if>     <br/> </xsl:template>  <xsl:template match="item" mode="follower">     <xsl:text> / </xsl:text>     <xsl:value-of select="name"/> </xsl:template> 

would work tweak on line before 1 says "main" , on line before 8 says "auxiliary class 1" , on line before 15 says "auxiliary class 2"?

how about:

<xsl:template match="studentitems">     <xsl:apply-templates select="item[position() mod 7 = 1]" mode="leader"/> </xsl:template>  <xsl:template match="item" mode="leader">     <xsl:choose>         <xsl:when test="position() = 1">main </xsl:when>         <xsl:when test="position() = 2">auxiliary class 1 </xsl:when>         <xsl:otherwise>auxiliary class 2 </xsl:otherwise>     </xsl:choose>     <xsl:value-of select="name"/>     <br/>     <xsl:apply-templates select="following-sibling::item[position() &lt;= 6 , position() mod 2]"/> </xsl:template>  <xsl:template match="item">     <xsl:value-of select="name"/>     <xsl:apply-templates select="following-sibling::item[1]" mode="follower"/>     <br/> </xsl:template>  <xsl:template match="item" mode="follower">     <xsl:text> / </xsl:text>     <xsl:value-of select="name"/> </xsl:template> 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -