'xsl:for-each repeating the first row
i left out the for-each end statements in previous post: here is a snap shot of the doc and the xsl including the end stmts. i made a change to code (removed the inline "<for-each end>" which changed the results. Now, there are two answers for each question BUT the first row is no longer repeated.
Document:
for-each-groupEXAM_QSTN_TXT
for-eachEXAM_ANSWR_TXT end end
BI Pub xsl dialog boxes:
<xsl:for-each-group select=".//row" group-adjacent="EXAM_QSTN_RECID">
<?for-each:current-group()?><?EXAM_ANSWR_TXT?>
<?end for-each?>
<?end for-each-group?>
New Result:
Test question text
TrueTrue
FalseFalse
/*****************************************************************/ Creating a template using Word w/BI Publisher. New to xsl code. Within a for-each-group, i have a for-each loop that is erroneously repeating the first row. Each record has the group value AND the child value. Data consists of each record containing: an exam question and answer text (with 2 - 4 "rows" as possible answers). The first "row" is used as the "exam question txt" in the for-each-group. The first row is ALSO the "first possible answer" in the for-each loop. Problem: the first (row) which is a possible answer is repeated at the end of the loop so template shows 5 possible answers not 4 (or in the example below 3 instead of 2 possible). Your help is greatly appreciated.
Here's the code:
<xsl:for-each-group select=".//row" group-adjacent="EXAM_QSTN_RECID">
<?for-each:current-group()?><?EXAM_ANSWR_TXT?><?end for-each?>
output:
True False question text
True
False
True
XML Word generated code:
<w:textInput>
<w:default w:val="for-each-group"/>
</w:textInput>
</w:ffData>
</w:fldChar>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:instrText xml:space="preserve"> FORMTEXT </w:instrText>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:fldChar w:fldCharType="separate"/>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:noProof/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:t>for-each-group</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:fldChar w:fldCharType="end"/>
</w:r>
<w:bookmarkEnd w:id="0"/>
<w:r w:rsidR="00360D93">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:fldChar w:fldCharType="begin">
<w:ffData>
<w:name w:val="Text1"/>
<w:enabled/>
<w:calcOnExit w:val="0"/>
<w:statusText w:type="text" w:val="<?ref:xdo0018?>"/>
<w:textInput>
<w:default w:val="EXAM_QSTN_TXT"/>
</w:textInput>
</w:ffData>
</w:fldChar>
</w:r>
<w:r w:rsidR="00360D93">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:instrText>FORMTEXT</w:instrText>
</w:r>
<w:r w:rsidR="00360D93">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
</w:r>
<w:r w:rsidR="00360D93">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:fldChar w:fldCharType="separate"/>
</w:r>
<w:r w:rsidR="00360D93">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:noProof/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:t>EXAM_QSTN_TXT</w:t>
</w:r>
<w:r w:rsidR="00360D93">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:fldChar w:fldCharType="end"/>
</w:r>
<w:r w:rsidR="00360D93">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:t xml:space="preserve"> </w:t>
</w:r>
<w:bookmarkStart w:id="1" w:name="Text5"/>
<w:r w:rsidR="00887F5C">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:fldChar w:fldCharType="begin">
<w:ffData>
<w:name w:val="Text5"/>
<w:enabled/>
<w:calcOnExit w:val="0"/>
<w:statusText w:type="text" w:val="<?ref:xdo0006?>"/>
<w:textInput>
<w:default w:val="for-each"/>
</w:textInput>
</w:ffData>
</w:fldChar>
</w:r>
<w:r w:rsidR="00887F5C">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:instrText xml:space="preserve"> FORMTEXT </w:instrText>
</w:r>
<w:r w:rsidR="00887F5C">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
</w:r>
<w:r w:rsidR="00887F5C">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:fldChar w:fldCharType="separate"/>
</w:r>
<w:r w:rsidR="00887F5C">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:noProof/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:t>for-each</w:t>
</w:r>
<w:r w:rsidR="00887F5C">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:fldChar w:fldCharType="end"/>
</w:r>
<w:bookmarkEnd w:id="1"/>
<w:r w:rsidR="00360D93">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:fldChar w:fldCharType="begin">
<w:ffData>
<w:name w:val="Text1"/>
<w:enabled/>
<w:calcOnExit w:val="0"/>
<w:statusText w:type="text" w:val="<?ref:xdo0019?>"/>
<w:textInput>
<w:default w:val="EXAM_ANSWR_TXT"/>
</w:textInput>
</w:ffData>
</w:fldChar>
</w:r>
<w:r w:rsidR="00360D93">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:instrText>FORMTEXT</w:instrText>
</w:r>
<w:r w:rsidR="00360D93">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
</w:r>
<w:r w:rsidR="00360D93">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:fldChar w:fldCharType="separate"/>
</w:r>
<w:r w:rsidR="00360D93">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:noProof/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:t>EXAM_ANSWR_TXT</w:t>
</w:r>
<w:r w:rsidR="00360D93">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:fldChar w:fldCharType="end"/>
</w:r>
<w:bookmarkStart w:id="2" w:name="Text2"/>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:fldChar w:fldCharType="begin">
<w:ffData>
<w:name w:val="Text2"/>
<w:enabled/>
<w:calcOnExit w:val="0"/>
<w:statusText w:type="text" w:val="<?ref:xdo0001?>"/>
<w:textInput>
<w:default w:val="end"/>
</w:textInput>
</w:ffData>
</w:fldChar>
</w:r>
<w:r>
Solution 1:[1]
Figured it out: XSL in Word w/BI Publisher:
Document:
for-each-group EXAM_QSTN_TXT
for-each EXAM_ANSWR_TXT end end
BI Pub dialog box for code:
<xsl:for-each-group select=".//row" group-adjacent="EXAM_QSTN_RECID">
<?for-each-group:current-group();./EXAM_ANSWR_RECID?>
<?end for-each-group?>
<?end for-each-group?>
Produces:
Test Question Text
multiple choice answer 1
multiple choice answer 2
etc.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ThanksfortheHelp |
