[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] for-each-group for multiple nodes
Hi List, I am using xslt v2.0 with saxon9 processor. I am not able to achieve my expected output through for-each-group for multiple nodes in a single template match. Please look into my detailed inputs and find mistakes in my below code. input xml ========= <?xml version="1.0" encoding="utf-8"?> <book xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/"> <para aid:pstyle="LevelF">Comprehension</para> <para aid:pstyle="LevelM">A Answer these questions briefly.</para> <para aid:pstyle="LevelM_sub">1. Where did Monu live?</para> <para aid:pstyle="LevelM_sub">2. What did the baker make?</para> <para aid:pstyle="LevelM">B Read these sentences from the story.</para> <para aid:pstyle="LevelM_sub">1. “Thief!” he cried. “You are stealing my smells.”</para> <para aid:pstyle="LevelM_sub">2. “Those smells come here on the air. I don't steal them.”</para> <para aid:pstyle="LevelM">C Read these sentences. Say if these sentences are true (T) or not true (NT).</para> <para aid:pstyle="LevelM">B Replace the words in colour with the number given in the brackets. Adds to the noun and rewrite the sentence.</para> <para aid:pstyle="LevelM_sub">1. I saw an orange. (four)</para> <para aid:pstyle="LevelF">Writing</para> <para aid:pstyle="LevelM">A Complete these sentences with words from the box. You will then have a summary of the story.</para> <para aid:pstyle="LevelM_sub">1. Monu was a ___________________.</para> <para aid:pstyle="LevelM_sub">2. He lived in a ________ above the baker's shop.</para> </book> xslt ===== <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" exclude-result-prefixes="aid"> <xsl:output method="xml" encoding="us-ascii" indent="yes" /> <xsl:template match="book"> <book> <xsl:for-each-group select="*" group-starting-with="para[contains(@aid:pstyle,'Level')]"> <xsl:choose> <xsl:when test="self::para/@aid:pstyle[contains(.,'LevelF')]"> <qandaset> <xsl:call-template name="g"> <xsl:with-param name="e" select="current-group()"/> </xsl:call-template> </qandaset> </xsl:when> <xsl:when test="self::para/@aid:pstyle[contains(.,'LevelM')]"> <question> <xsl:call-template name="g"> <xsl:with-param name="e" select="current-group()"/> </xsl:call-template> </question> </xsl:when> <xsl:otherwise> <xsl:call-template name="g"> <xsl:with-param name="e" select="current-group()"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </book> </xsl:template> <xsl:template name="g"> <xsl:param name="e"/> <xsl:for-each-group select="$e" group-adjacent="string(self::para/@aid:pstyle)"> <xsl:choose> <xsl:when test="self::para/@aid:pstyle[contains(.,'LevelF')]"> <title> <xsl:apply-templates select="current-group()"/> </title> </xsl:when> <xsl:when test="self::para/@aid:pstyle[contains(.,'LevelM_sub')]"> <para> <xsl:apply-templates select="current-group()"/> </para> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:template> </xsl:stylesheet> Transformed output ================== <?xml version="1.0" encoding="us-ascii"?> <book> <qandaset> <title>Comprehension</title> </qandaset> <question>A Answer these questions briefly.</question> <question> <para>1. Where did Monu live?</para> </question> <question> <para>2. What did the baker make?</para> </question> <question>B Read these sentences from the story. Answer the questions that follow.</question> <question> <para>1. “Thief!” he cried. “You are stealing my smells.”</para> </question> <question> <para>2. “Those smells come here on the air. I don't steal them.”</para> </question> <question>C Read these sentences. Say if these sentences are true (T) or not true (NT).</question> <question>B Replace the words in colour with the number given in the brackets. Adds to the noun and rewrite the sentence.</question> <question> <para>1. I saw an orange. (four)</para> </question> <qandaset> <title>Writing</title> </qandaset> <question>A Complete these sentences with words from the box. You will then have a summary of the story.</question> <question> <para>1. Monu was a ___________________.</para> </question> <question> <para>2. He lived in a ________ above the baker's shop.</para> </question> </book> Expected output =============== <?xml version="1.0" encoding="us-ascii"?> <book> <qandaset> <title>Comprehension</title> <question>A Answer these questions briefly. <para>1. Where did Monu live?</para> <para>2. What did the baker make?</para> </question> <question>B Read these sentences from the story. Answer the questions that follow. <para>1. “Thief!” he cried. “You are stealing my smells.”</para> <para>2. “Those smells come here on the air. I don't steal them.”</para> </question> <question>C Read these sentences. Say if these sentences are true (T) or not true (NT).</question> <question>B Replace the words in colour with the number given in the brackets. Adds to the noun and rewrite the sentence. <para>1. I saw an orange. (four)</para> </question> </qandaset> <qandaset> <title>Writing</title> <question>A Complete these sentences with words from the box. You will then have a summary of the story. <para>1. Monu was a ___________________.</para> <para>2. He lived in a ________ above the baker's shop.</para> </question> </qandaset> </book> Regards, Ramkumar
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|