2011-01-25 5 views
0

XML 문서에서 두 개의 개별 숫자를 어떻게 일치시킬 수 있습니까? 내 XML 문서에는 <PgIndexElementInfo> 요소가 여러 개 있습니다. 각 요소는 각각 고유 한 <ID>이있는 다른 탐색 요소를 나타냅니다. 문서의 뒷부분에있는 <PageID>은 위에 사용 된 <ID>과 일치하는 번호를 지정합니다. 위에 명시된 <ID><PageID>을 어떻게 대응시킬 수 있습니까?요소 ID에 대한 PAGEID를 일치하는 XSLT

<Element> 
    <Content> 
     <PgIndexElementInfo> 
      <ElementData> 
       <Items> 
        <PgIndexElementItem> 
         <ID>1455917</ID> 
        </PgIndexElementItem> 
       </Items> 
      </ElementData> 
     </PgIndexElementInfo> 
    </Content> 
</Element> 
<Element> 
    <Content> 
     <CustomElementInfo> 
      <PageID>1455917</PageID> 
     </CustomElementInfo> 
    </Content> 
</Element> 

편집 :

나는 내 코드에 아래의 솔루션을 추가했습니다. 존재하는 xsl:apply-templates은 HTML과 XML 사이에서 손실되는 중첩 목록을 다시 만드는 데 사용됩니다. 지금해야 할 일은 PageID를 <PgIndexElementItem>의 ID와 일치시키고 CSS 클래스를 <ul>에 추가하는 것입니다. 나는 그것이 의미가 있기를 바랍니다.

<xsl:key name="kIDByValue" match="ID" use="."/> 
<xsl:template match="PageID[key('kIDByValue',.)]"> 
    <xsl:apply-templates select="//PgIndexElementItem[not(contains(Description, '.'))]" /> 
</xsl:template> 

<xsl:template match="PgIndexElementItem"> 
    <li> 
    <a href="{ResolvedURL/Absolute}"><xsl:value-of select="Title"/></a> 
    <xsl:variable name="prefix" select="concat(Description, '.')"/> 
    <xsl:variable name="childOptions" 
     select="../PgIndexElementItem[starts-with(Description, $prefix) 
     and not(contains(substring-after(Description, $prefix), '.'))]"/> 
    <xsl:if test="$childOptions"> 
     <ul> 
     <xsl:apply-templates select="$childOptions" /> 
     </ul> 
    </xsl:if> 
    </li> 
</xsl:template> 

답변

3

크로스 레퍼런스를 처리하는 XSLT 방식은 키를 사용합니다.

일치 사항 : ID 요소에 의해 참조 된 모든 PageID 요소와 일치하는 규칙. 선택

<xsl:key name="kIDByValue" match="ID" use="."/> 
<xsl:template match="PageID[key('kIDByValue',.)]"> 
    <!-- Template content --> 
</xsl:template> 

: 특이 값마다 PageID 요소를 선택하는 식이다.

<xsl:key name="kPageIDByValue" match="PageID" use="."/> 
<xsl:template match="ID"> 
    <xsl:apply-templates select="key('kPageIDByValue',.)"/> 
</xsl:template> 
+0

정답은 –

+0

입니다.' jrottier

관련 문제