2013-06-10 1 views
0

XML 목록에 다음 코드 집합이 있고 내용을 추출하는 데 다음 XSLT가 사용되지만 작동하지 않습니다. 처음부터 끝까지 잘 작동하지만 가운데 하나가 문제를 만듭니다. 어떤 도움을 주시기 바랍니다 .......XSLT 통해 나열

XML :

<cl:sect1 identifier="ZQRRUG590702676" number="nonumber"> 
    <cl:complex-meta> 
    <cl:title identifier="PLHOOC548347957">Questions for Review and Reflection</cl:title> 
    </cl:complex-meta> 
    <cl:quiz identifier="UUHXZX749864214"> 
    <cl:metadata-wrapper> 
    <cl:descriptive-meta> 
    <cl:broad-term>Chapter exercises</cl:broad-term> 
    </cl:descriptive-meta> 
    </cl:metadata-wrapper> 
    <cl:question-section identifier="LMUGHP665075315"> 
    <cl:short-answer-section identifier="PDWZPT096484135"> 
    <cl:quiz-meta> 
    <cl:numbering role="style" target-node="question">arabic</cl:numbering> 
    </cl:quiz-meta> 
    <cl:sa-item identifier="DHUJEX954944222"> 
<cl:question identifier="ZXPROB877164447"><cl:para identifier="UVPIYI046459379">Choose one of the theoretical perspectives on the family, and discuss how you might use it to understand something about life in <cl:style identifier="XWHGPG736884704" styles="italic">your</cl:style> family.</cl:para></cl:question> 
    </cl:sa-item> 
    <cl:sa-item identifier="XLIHNY049827846"> 
    <cl:question identifier="WBNMFT023816273"><cl:para identifier="MVVFTE506398129">Choose a magazine photo and analyze its content from one of the perspectives de-scribed in this chapter. Then analyze the photo from another theoretical perspective. How do your insights differ depending on which theoretical perspective is used?</cl:para></cl:question> 
    </cl:sa-item> 
    <cl:sa-item identifier="KHOISZ206843547"> 
    <cl:question identifier="YIRLTY425252173"><cl:para identifier="DEAOVV858913951">Discuss why science is often considered a better way to gain knowledge than is personal experience alone. When might this not be the case?</cl:para></cl:question> 
    </cl:sa-item> 
    <cl:sa-item identifier="UZUXJL108947882"> 
    <cl:question identifier="NOBHFC190777617"><cl:para identifier="CISHBM348415557">Think of a research topic, then review the data-gathering techniques described in this chapter to decide which of these you might use to investigate your topic.</cl:para></cl:question> 
    </cl:sa-item> 
    <cl:sa-item identifier="ZITOCE439682847"> 
    <cl:question identifier="MCRAPB388676722"><cl:para identifier="RTRSPD372632657"><cl:key-term-entry identifier="JTBDZT820091835"><cl:key-term identifier="VSNZVL072560329">Policy Question</cl:key-term></cl:key-term-entry>. What aspect of family life would it be helpful for policy makers to know more about as they make law and design social programs? How might this topic be researched? Is it controversial?</cl:para></cl:question> 
    </cl:sa-item> 
    </cl:short-answer-section> 
    </cl:question-section> 
    </cl:quiz> 
    </cl:sect1> 

XSLT :

<xsl:template match="cl:closer/cl:sect1/cl:quiz/cl:question-section/cl:short-answer-section/cl:sa-item[1]/cl:question[1]/cl:para"> 
       <xsl:element name="ParagraphStyleRange"> 
        <xsl:attribute name="AppliedParagraphStyle">ParagraphStyle/EOCNLF</xsl:attribute> 
        <xsl:apply-templates/> 
       </xsl:element> 
</xsl:template> 
<xsl:template match="cl:closer/cl:sect1/cl:quiz/cl:question-section/cl:short-answer-section/cl:sa-item[not(position() = last())]/cl:question[not(position()=last())]/cl:para"> 
       <xsl:element name="ParagraphStyleRange"> 
        <xsl:attribute name="AppliedParagraphStyle">ParagraphStyle/EOCNLM</xsl:attribute> 
        <xsl:apply-templates/> 
       </xsl:element> 
</xsl:template> 
<xsl:template match="cl:closer/cl:sect1/cl:quiz/cl:question-section/cl:short-answer-section/cl:sa-item[position()=last()]/cl:question[position()=last()]/cl:para"> 
       <xsl:element name="ParagraphStyleRange"> 
        <xsl:attribute name="AppliedParagraphStyle">ParagraphStyle/EOCNLL</xsl:attribute> 
        <xsl:apply-templates/> 
       </xsl:element> 
</xsl:template> 

답변

0

귀하의 모든 sa-item 요소 따라서 정확히 하나의 question 아이가

cl:sa-item[not(position() = last())]/cl:question[not(position()=last())] 

아무것도 일치하지 않습니다 (question p 내에 있기 때문에). position()last()을 모두 다시 처리하면 항상 1입니다. question 단계에서 검색어를 삭제하면됩니다. 즉, question 요소가 아닌 sa-item의 색인 만 템플릿에서 확인하도록하면됩니다. 이 작업을 수행하는 가장 깨끗한 방법은 우선 순위가 될 것입니다 :

<xsl:template priority="3" match="cl:sa-item[1]/cl:question/cl:para"> 
    <!--...--> 
</xsl:template> 

<xsl:template priority="2" match="cl:sa-item[last()]/cl:question/cl:para"> 
    <!--...--> 
</xsl:template> 

<xsl:template priority="1" match="cl:sa-item/cl:question/cl:para"> 
    <!--...--> 
</xsl:template> 

이 방법은 첫 번째 템플릿은 두 번째는 last() (가정이 또한 처음이 아니다 데리러, 최초의 sa-item를 데리러 , short-answer-section에 항목이 하나 뿐인 경우), 세 번째 항목은 처음 두 개의 우선 순위가 높은 첫 번째 서식 파일에서 소비하지 않는 항목을 모두 선택합니다.

+0

감사합니다. Ian! 정말 고마워. 대단히 감사합니다. –

+0

@ UmeshKahali 도움이 된 것을 기쁘게 생각합니다. 스택 오버플로에서 올바른 답을 누군가에게 감사하는 일반적인 방법은 대답의 왼쪽에있는 눈금을 클릭하여 _accept_하는 것입니다. 이렇게하면 자신의 평판 점수가 향상됩니다. –