2014-10-23 3 views
0

I 다음 XML 코드가 있습니다: 대한-각

FOR EACH ENTRY inside `Collection/Content/`: 

    Html/root/Location/location (if not blank show it) 
    Html/root/Location/Address { 
     /Address1 
     /Address2 (if not blank show it) 
     /City 
     /State 
     /zip 
     /phone 
     /fax (if not blank show it) 
    } 

    Html/root/Location/location (if not blank show it) 
    Html/root/Location/Address { 
     /Address1 
     /Address2 (if not blank show it) 
     /City 
     /State 
     /zip 
     /phone 
     /fax (if not blank show it) 
    } 

    Html/root/Location/location (if not blank show it) 
    Html/root/Location/Address { 
     /Address1 
     /Address2 (if not blank show it) 
     /City 
     /State 
     /zip 
     /phone 
     /fax (if not blank show it) 
    } 

내가 :

<?xml version="1.0" encoding="UTF-8"?> 
<Collection> 
    <Content> 
     <ID>12</ID> 
     <Type>Content</Type> 
     <Title>Office Location #1</Title> 
     <QuickLink>/office.aspx?id=12</QuickLink> 
     <Teaser> 
      <p> 
       <span class="infoBold">My Group</span> 
       <br /> 
       WPO 
       <br /> 
       Office Location #1 
       <br /> 
       Wp, NY 090801 
       <br /> 
       986.362.3265 
      </p> 
     </Teaser> 
     <Html> 
      <root> 
       <Location> 
        <location /> 
        <office>WPO</office> 
        <Address> 
         <image> 
          <img src="someing.png" /> 
         </image> 
         <Address1>Office Location #1</Address1> 
         <Address2 /> 
         <City>Wp</City> 
         <State>NY</State> 
         <zip>09081</zip> 
         <phone>986.362.3265</phone> 
         <fax /> 
         <urgent_care_phone /> 
        </Address> 
       </Location> 
      </root> 
     </Html> 
    </Content> 
    <Content> 
     <ID>48</ID> 
     <Type>Content</Type> 
     <Title>Office Location #3</Title> 
     <QuickLink>/office.aspx?id=48</QuickLink> 
     <Teaser> 
      <p> 
       <span class="infoBold">My Group</span> 
       <br /> 
       WPO 
       <br /> 
       Office Location #3 
       <br /> 
       Wp, NY 090801 
       <br /> 
       986.362.3265 
      </p> 
     </Teaser> 
     <Html> 
      <root> 
       <Location> 
        <location /> 
        <office>WPO</office> 
        <Address> 
         <image> 
          <img src="someing.png" /> 
         </image> 
         <Address1>Office Location #3</Address1> 
         <Address2 /> 
         <City>Wp</City> 
         <State>NY</State> 
         <zip>09081</zip> 
         <phone>986.362.3265</phone> 
         <fax /> 
         <urgent_care_phone /> 
        </Address> 
       </Location> 
      </root> 
     </Html> 
    </Content> 
    <Content> 
     <ID>36</ID> 
     <Type>Content</Type> 
     <Title>Office Location #2</Title> 
     <QuickLink>/office.aspx?id=36</QuickLink> 
     <Teaser> 
      <p> 
       <span class="infoBold">My Group</span> 
       <br /> 
       WPO 
       <br /> 
       Office Location #2 
       <br /> 
       Wp, NY 090801 
       <br /> 
       986.362.3265 
      </p> 
     </Teaser> 
     <Html> 
      <root> 
       <Location> 
        <location>WP</location> 
        <office>WPO</office> 
        <Address> 
         <image> 
          <img src="someing.png" /> 
         </image> 
         <Address1>Office Location #2</Address1> 
         <Address2 /> 
         <City>Wp</City> 
         <State>NY</State> 
         <zip>09081</zip> 
         <phone>986.362.3265</phone> 
         <fax /> 
         <urgent_care_phone /> 
        </Address> 
       </Location> 
      </root> 
     </Html> 
    </Content> 
</Collection> 

나는 다음과 같은 형식을 표시 할을 얻기 위해 노력 QuickLink

<xsl:for-each select="Collection/Content/Html"> 
    <div class="serviceHolder brClear"> 
     <xsl:value-of select="root/Location/Address/Address1" /> 
     <xsl:value-of select="root/Location/Address/Address2" /> 
     <xsl:value-of select="root/Location/Address/City" /> 
     <xsl:value-of select="root/Location/Address/State" /> 
     <xsl:value-of select="root/Location/Address/zip" /> 
     <xsl:value-of select="root/Location/Address/phone" /> 
     <a href="{QuickLink}" title="Test">Get Direction</a> 
    </div> 
</xsl:for-each> 

나는를위한 각각의 Collection/Content/Html을 사용하고 있지만, 변경하여 xsl:for-each 내 컨텍스트 노드에 QuickLink 상대적으로 XPath를하기 위해선, a 세대 문제에 대한

<a href="{QuickLink}" title="Test">Get Direction</a> 
+2

유용한 응답을 얻으려면 코드가 모두 표시되고 원하는 출력이 원하는대로 미리 설정되어 있는지 확인하십시오. (예 : HTML을 원하면 HTML을 쓰고 중괄호, 괄호 및 슬래시를 모호하지 않게 작성하십시오.) – Tomalak

+2

또한 제목을 올바르게 선택하십시오. 이것은 "XSLT를 사용하여 XML을 브라우저에 표시하는 방법"이 아닙니다. 이것은'xsl : for-each' 구조 안의/근처에있는 코드와 관련된 일상적인 XPath 선택에 관한 것입니다. * XPath를 사용하여 xsl : for-each *의 정상적인 순서를 벗어난 노드를 선택합니다. – kjhughes

+0

감사합니다. 나는 그것이 지금 더 이해된다라고 생각한다. 그래서 어떤 아이디어가'QuickLink'를 얻는가 – SearchForKnowledge

답변

1

: 어떻게 앵커 여기 링크 Collection/Content/QuickLink로 돌아 가야합니까

<a href="{QuickLink}" title="Test">Get Direction</a> 

<a href="{../QuickLink}" title="Test">Get Direction</a> 

XSLT를 작성하여 HTML의 의사 마크 업을 생성하는 방법은 당신을 위해 코드를 작성하는 것보다 특정 질문을 돕는 것을 선호합니다. 다른 특정 질문이 있으면 알려주십시오.

+0

고마워. 그게 내가 알아야 할 전부다. :) – SearchForKnowledge