2012-06-11 2 views
0

존재 여부에 관계없이 4 가지 질문을 작성하고 싶습니다. 지금까지는 3 가지 의견을 모두 검색하는 "NTE_NotesAndCommentsSegment_2/NTE_3_Comment"를 선택했습니다. 그러나 나는 그것이 질문 4 문제는 존재하지 않는 밖으로 쓰기 "질문 1" (문자열 값)XSLT 선택 항목에 "값"이 포함 된 경우

  • 을 포함하는 경우 NTE_3_Comment을 선택

    1. 에 문제가 있어요.

    2. 또한 SETID의 올바른 번호를 출력해야합니다.

    참고 : 질문에 실제로 숫자가 들어 있지 않습니다. ID를 사용하여 출력을 정렬하고 있습니다.

    입력 XML :

    <NTE_NotesAndCommentsSegment_2> 
        <NTE_1_SetIdNotesAndComments>1</NTE_1_SetIdNotesAndComments> 
        <NTE_2_SourceOfComment></NTE_2_SourceOfComment> 
        <NTE_3_Comment>Question 1 ? Answer 1</NTE_3_Comment> 
    </NTE_NotesAndCommentsSegment_2> 
    <NTE_NotesAndCommentsSegment_2> 
        <NTE_1_SetIdNotesAndComments>1</NTE_1_SetIdNotesAndComments> 
        <NTE_2_SourceOfComment></NTE_2_SourceOfComment> 
        <NTE_3_Comment>Question 2 ? Answer 2</NTE_3_Comment> 
    </NTE_NotesAndCommentsSegment_2> 
    <NTE_NotesAndCommentsSegment_2> 
        <NTE_1_SetIdNotesAndComments>1</NTE_1_SetIdNotesAndComments> 
        <NTE_2_SourceOfComment></NTE_2_SourceOfComment> 
        <NTE_3_Comment>Question 3? Answer 3</NTE_3_Comment> 
    </NTE_NotesAndCommentsSegment_2> 
    

    예상 출력 XML : 나는 날이 솔루션에 내 접근 방식을 변경할 수 있습니다 제안을 찾고 있어요

    <NTE_NotesAndCommentsSegment_2> 
        <NTE_1_SetIdNotesAndComments>1</NTE_1_SetIdNotesAndComments> 
        <NTE_2_SourceOfComment></NTE_2_SourceOfComment> 
        <NTE_3_Comment>Question 1 ? Answer 1</NTE_3_Comment> 
    </NTE_NotesAndCommentsSegment_2> 
    <NTE_NotesAndCommentsSegment_2> 
        <NTE_1_SetIdNotesAndComments>2</NTE_1_SetIdNotesAndComments> 
        <NTE_2_SourceOfComment></NTE_2_SourceOfComment> 
        <NTE_3_Comment>Question 2 ? Answer 2</NTE_3_Comment> 
    </NTE_NotesAndCommentsSegment_2> 
    <NTE_NotesAndCommentsSegment_2> 
        <NTE_1_SetIdNotesAndComments>3</NTE_1_SetIdNotesAndComments> 
        <NTE_2_SourceOfComment></NTE_2_SourceOfComment> 
        <NTE_3_Comment>Question 3 ? Answer 3</NTE_3_Comment> 
    </NTE_NotesAndCommentsSegment_2> 
    <NTE_NotesAndCommentsSegment_2> 
        <NTE_1_SetIdNotesAndComments>4</NTE_1_SetIdNotesAndComments> 
        <NTE_2_SourceOfComment></NTE_2_SourceOfComment> 
        <NTE_3_Comment>Question 4 ? *Blank* </NTE_3_Comment> 
    </NTE_NotesAndCommentsSegment_2> 
    

    . 미리 감사드립니다.

    해결책 : @ O.R.Mapper 제안에 감사드립니다. 네 가지 질문 모두는 질문의 존재 여부와 상관없이 항상 작성됩니다. 소스에 질문이 없으면 답은 공백으로 표시됩니다.

      <NTE_NotesAndCommentsSegment_2> 
          <NTE_1_SetIdNotesAndComments>1</NTE_1_SetIdNotesAndComments> 
          <NTE_3_Comment>Question 1 ?<xsl:value-of select="substring-after(//NTE_NotesAndCommentsSegment_2/NTE_3_Comment[starts-with(text(),'Question 1')],'?')"/> 
          </NTE_3_Comment> 
          </NTE_NotesAndCommentsSegment_2> 
    
          <NTE_NotesAndCommentsSegment_2> 
          <NTE_1_SetIdNotesAndComments>2</NTE_1_SetIdNotesAndComments> 
          <NTE_3_Comment>Question 2 ?<xsl:value-of select="substring-after(//NTE_NotesAndCommentsSegment_2/NTE_3_Comment[starts-with(text(),'Question 2')],'?')"/> 
          </NTE_3_Comment> 
          </NTE_NotesAndCommentsSegment_2> 
    
          <NTE_NotesAndCommentsSegment_2> 
          <NTE_1_SetIdNotesAndComments>3</NTE_1_SetIdNotesAndComments> 
          <NTE_3_Comment>Question 3 ?<xsl:value-of select="substring-after(//NTE_NotesAndCommentsSegment_2/NTE_3_Comment[starts-with(text(),'Question 3')],'?')"/> 
          </NTE_3_Comment> 
          </NTE_NotesAndCommentsSegment_2> 
    
          <NTE_NotesAndCommentsSegment_2> 
          <NTE_1_SetIdNotesAndComments>4</NTE_1_SetIdNotesAndComments> 
          <NTE_3_Comment>Question 4 ? <xsl:value-of select="substring-after(//NTE_NotesAndCommentsSegment_2/NTE_3_Comment[starts-with(text(),'Question 4')],'?')"/> 
          </NTE_3_Comment> 
          </NTE_NotesAndCommentsSegment_2> 
    
  • +0

    당신은 "선택 NTE_3_Comment 무엇을 의미합니까 질문 1이 들어있는 곳은 어디입니까? " –

    +0

    특정 문자열을 찾고 있습니다. 이 예제에서 나는 "질문 1"을 찾고있을 것입니다. –

    +0

    이 정보는 BizTalk 맵과 관련되어 있으므로 원본 및 대상 스키마 (파트)를 추가하면 도움이 될 수 있습니다. 원본'NTE_1_SetIdNotesAndComments'는 실제로 항상 '1' 값을 갖고 있습니까? – Filburt

    답변

    0

    (1) 다음 XPath 식 것를위한 솔루션 :

    //NTE_NotesAndCommentsSegment_2/NTE_3_Comment[starts-with(text(), 'Question 1')] 
    
    +0

    나는 OP가 오히려 요소 텍스트를 "?"앞에 질문 부분으로 나누는 방법을 찾고 있다고 생각한다. 와 답 부분 ("?"다음)을 텍스트를 자신의 xpath로 하드 코딩하는 것보다 더 낫습니다. – Filburt

    +0

    @ O.R.Mapper, 당신의 제안은 올바른 방향으로 나를 지적했습니다. 'substring-after (// NTE_NotesAndCommentsSegment_2/NTE_3_Comment [starts-with (text(), 'Question 1)],'? ')'해결책을 완료하면 완전한 답을 제공 할 것입니다. –

    0

    전체 XSLT 솔루션은 다음과 같을 수는 :

    <?xml version="1.0" encoding="utf-8"?> 
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
        <xsl:output method="xml" indent="yes" /> 
    
        <xsl:template match="/"> 
         <xsl:apply-templates /> 
        </xsl:template> 
    
        <xsl:template match="root"> 
         <root> 
          <xsl:call-template name="for.loop"> 
           <xsl:with-param name="i" select="1" /> 
           <xsl:with-param name="count" select="4" /> 
           <xsl:with-param name="answer" select="substring-after(//NTE_NotesAndCommentsSegment_2[position() = 1]/NTE_3_Comment, '?')" /> 
          </xsl:call-template> 
         </root> 
        </xsl:template> 
    
        <xsl:template name="for.loop"> 
    
         <xsl:param name="i" /> 
         <xsl:param name="count" /> 
         <xsl:param name="answer" /> 
    
         <xsl:if test="$i &lt;= $count"> 
          <NTE_NotesAndCommentsSegment_2> 
           <NTE_1_SetIdNotesAndComments> 
            <xsl:value-of select="$i" /> 
           </NTE_1_SetIdNotesAndComments> 
           <NTE_2_SourceOfComment></NTE_2_SourceOfComment> 
           <NTE_3_Comment> 
           <xsl:choose> 
            <xsl:when test="$answer = ''"> 
             <xsl:value-of select="concat('Question ', $i, ' ? *Blank*')" /> 
            </xsl:when> 
            <xsl:otherwise> 
             <xsl:value-of select="concat('Question ', $i, ' ? ', $comment)"/> 
            </xsl:otherwise> 
           </xsl:choose> 
           </NTE_3_Comment> 
          </NTE_NotesAndCommentsSegment_2> 
         </xsl:if> 
    
         <!-- Repeat the loop until finished --> 
         <xsl:if test="$i &lt;= $count"> 
          <xsl:call-template name="for.loop"> 
           <xsl:with-param name="i" select="$i + 1" /> 
           <xsl:with-param name="count" select="$count"> 
           <xsl:with-param name="comment" select="substring-after(//NTE_NotesAndCommentsSegment_2[position() = $i + 1]/NTE_3_Comment, '?')" /> 
          </xsl:call-template> 
         </xsl:if> 
    
        </xsl:template> 
    
        <xsl:template match="/ | @* | node()"> 
         <xsl:copy> 
          <xsl:apply-templates select="@* | node()"/> 
         </xsl:copy> 
        </xsl:template> 
    
    </xsl:stylesheet> 
    
    +0

    감사의 말 Filburt,이 솔루션은 대답 만 출력합니다. 출력물에 그것을 포함시키기 위해 어떤 질문이 존재하지 않는지를 아는 것이 중요합니다. –

    +0

    출력에 시퀀스를 포함하도록 내 대답을 업데이트했습니다.실제 데이터에 시퀀스 번호가 포함되어 있지 않다고 말씀 하셨기 때문에 xpath'starts-with (text(), 'Question X')'가 작동한다는 사실을 다소 혼란스러워합니다. – Filburt

    +0

    정확함, 나는이 예에 충실하고 올바르게 대답하고 싶었다. Filburt에는 시퀀스 번호가 포함되어 있지 않지만 4 가지 질문이 무엇인지 알 수 있습니다. '시험 목적? 연간 물리학 '은 목적 부분 문자열로 시작합니까? 내게'연례 물리적 인'을 준다. 또한 질문이 올바른 순서로 오지 않을 수도 있습니다. 올바른 순서로 출력해야합니다. 감사합니다 시간 Filburt –

    관련 문제