2014-06-16 4 views
0

아래 XML이 있습니다.다른 경우로 구분하고 연결하십시오.

<orderedlist type="manual"> 
<item num="1."><para>identify the issues in dispute;</para></item> 
<item num="1.1"><para>explore and generate options;</para></item> 
<item num="1.1.1"><para>communicate with one another; and/or</para></item> 
<item num="(i)"><para>copy of the cancellation of employment pass; and</para></item> 
<orderedlist> 

여기에 내가 item-num의 모든 .-에 번역 및 . 이전에 내가 해결책을받은 나는 not(ends-with(./@num,'.'))을 사용한 후 일부 번호 또는 기간이 다른 태그로 둘러싸 싶다. 그것도 괜찮 았던 점까지, 최근에 나는 에있는 값이 (i), i, a, a)과 같은 조건을 가지고 있으며 새로운 tag을 얻는 상황 (위의 XML에서 4 번째 item num)을 발견했습니다. 아래는 내 XSL 템플릿입니다. 내가 X.XX.X.X를 포맷보다

<xsl:template name="orderedlist" match="orderedlist"> 
     <ol class="eng-orderedlist orderedlist"> 
      <xsl:apply-templates/> 
     </ol> 
    </xsl:template> 


<xsl:template match="item"> 
    <xsl:call-template name="paran"></xsl:call-template> 
</xsl:template> 


<xsl:template name="paran"> 
<xsl:apply-templates select="./para/node()[1][self::page]" mode="first"/> 
     <li class="item"> 
     <div class="para"> 

<xsl:choose> 
    <xsl:when test="not(ends-with(./@num,'.'))"> 
     <a name="{translate(./@num,'.','-')}"/> 
    <span class="phrase"> 
    <xsl:value-of select="./@num"></xsl:value-of> 
    </span> 
</xsl:when> 
<xsl:when test="./@num"> 
    <span class="item-num"> 
    <xsl:value-of select="./@num"></xsl:value-of> 
    </span> 
</xsl:when> 
</xsl:choose> 

    <xsl:apply-templates/> 
     </div> 
     </li> 
</xsl:template> 

<xsl:template match="page[not(preceding-sibling::node()[not(self::text()) or normalize-space()])]"/> 

여기에 내가 다른 숫자의 주위에 phrase를 원하지 않는다.

이 호의 데모는 here입니다.

어떻게 해결할 수 있는지 알려 주시기 바랍니다.

감사

+0

예상되는 결과는 무엇입니까? – helderdarocha

+1

지난 몇 주 동안 여러 가지 매우 비슷한 질문을했습니다. 이전에 XSLT 2.0을 사용하고 있다고 지적 했으므로 [이전 질문 중 하나에 대한 내 대답]에 대한 의견에서 제안한 내용을 다시 한 번 추천합니다 (http://stackoverflow.com/a/24040621/592139).) - 당신이 찾고있는 구조는 정규 표현식으로 콤팩트하게 표현 될 수 있으므로'matches' 함수를 사용하여 그것을 테스트 할 수 있습니다. –

+0

안녕하세요 @helderdarocha, 예상 출력은'XX' 또는'XXX' 형식의'item num'과 떨어져 있고, 다른 모든 item-num은'' 그러나 ' – user2423959

답변

2

은 아마도 당신은 NUM 속성은 처음에 전체 정지가 포함되어 있는지 여부에 대한 검사를 추가 할 필요가

<xsl:when test="contains(@num, '.') and not(ends-with(./@num,'.'))"> 

@num 전체 중지를 포함하지만 상기하지 하나 종료.

2

나는 당신이이 방법을 건의 할 것입니다 :

<xsl:template match="item"> 
    <!-- do one thing here --> 
</xsl:template> 

<xsl:template match="item [not(ends-with(@num, '.'))] [not (translate(@num, '.123456789', ''))]"> 
<!-- do another thing here --> 
</xsl:template> 

-
아마 더 우아한 것 이안 로버츠에 의해 제안 정규식으로 술어를 수행.

관련 문제