2012-11-05 2 views
0

XSL에 대한 완전한 멍청하다고 말함으로써 시작하겠습니다. 나는 내가 생각하기에 매우 간단하다고 생각하고 있지만 구문을 이해하는 데 어려움을 겪고 있습니다.XSL과 연결

나는 위치 이름 (예. 시카고 또는 올랜드)

가 그럼 난 지역 번호없이 전화 번호를 가져옵니다 변수를 가져옵니다 변수가 있습니다.

내가하려고하는 것은 위치가 Chicago (773) 또는 Orland (708) 인 경우 Concat ("전화 번호"가있는 지역 번호)라는 If 문입니다.

변수 :

xsl:variable name="haswph"  select="string-length(workphone) > 0" 
xsl:variable name="hasonum"  select="string-length(officenumber) > 0" 

출력 :

<xsl:if test="$haswph"> 
    <li id="PhoneField"> 
     <xsl:apply-templates select="hithighlightedproperties/workphone" /> 
    </li> 
    </xsl:if> 
    <xsl:if test="$hasonum"> 
    <li id="OfficeField"> 
     <xsl:apply-templates select="hithighlightedproperties/officenumber" /> 
    </li> 
    </xsl:if> 

어떤 제안 또는 올바른 방향으로 점을 크게 감상 할 수있다.

감사합니다, 브랜든

<preferredname>Nigro, Brandon L.</preferredname> 
<yomidisplayname></yomidisplayname> 
<department>Information Technology</department> 
<workphone>555-5555</workphone> 
<officenumber>John Academic Center</officenumber> 
+1

게시물을 편집하여 입력 XML 샘플과 원하는 출력을 포함하십시오. 또한, 입력에서 "위치"는 어디입니까? 사무실이 시카고 또는 올랜도인지 결정하지 않은 경우 –

+0

AD에서 오는 xsl은 SharePoint 웹 파트의 청크입니다. –

+0

괜찮아요.하지만 여전히 XML "위치"의 출처와 입출력 샘플을 볼 필요가 있습니다. –

답변

0

내가 제대로 질문을 이해한다면, 해결책은 단순히 현재 XSL에이 템플릿을 추가 통과 :

<xsl:template match="workphone"> 
    <xsl:if test="$office='Chicago'">(773) </xsl:if> 
    <xsl:if test="$office='Orland'">(708) </xsl:if> 
    <xsl:value-of select="."/> 
</xsl:template> 

에 의해이 "$ 사무소"변수를 교체 원래 게시물에서 추천 한 사람입니다.

편집 : 여기가 이전 템플릿 샘플 입력 XML에 적용되는 AA 완전한 어트 변환이 (BTW :. 미래의 게시물에서 대신 그 부분의 포스트 완전한 입력/출력 XML 짐 개리슨의 제안을 다음과 같은 시도하고 첫 번째 시도에서 정확한 응답을 얻을 수 있습니다).

입력 :

<Office code="Chicago"> 
     <Employee id="1"> 
      <hithighlightedproperties> 
       <preferredname>Nigro, Brandon L.</preferredname> 
       <yomidisplayname></yomidisplayname> 
       <department>Information Technology</department> 
       <workphone>555-5555</workphone> 
       <officenumber>John Academic Center</officenumber> 
      </hithighlightedproperties> 
     </Employee> 
    </Office> 

XSL :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="html" indent="yes"/> 
    <xsl:variable name="office" select="Office/@code"/> 
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
    <xsl:template match="Office"> 
     <html> 
      <body> 
       <xsl:apply-templates select="Employee"/> 
      </body> 
     </html> 
    </xsl:template> 
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
    <xsl:template match="Employee"> 
     <xsl:variable name="haswph" select="string-length(hithighlightedproperties/workphone) &gt; 0"/> 
     <xsl:variable name="hasonum" select="string-length(hithighlightedproperties/officenumber)&gt; 0"/> 
     <p>Employee <xsl:value-of select="@id"/> Properties</p> 
     <ul> 
      <li id="Name"><xsl:value-of select="hithighlightedproperties/preferredname"/></li> 
      <xsl:if test="string-length(hithighlightedproperties/yomidisplayname)"> 
       <li id="DisplayNameField"> 
        <xsl:apply-templates select="hithighlightedproperties/yomidisplayname"/> 
       </li> 
      </xsl:if> 
      <li id="DepartmentField"><xsl:value-of select="hithighlightedproperties/department"/></li> 
      <xsl:if test="$haswph"> 
       <li id="PhoneField"> 
        <xsl:apply-templates select="hithighlightedproperties/workphone"/> 
       </li> 
      </xsl:if> 
      <xsl:if test="$hasonum"> 
       <li id="OfficeField"> 
        <xsl:apply-templates select="hithighlightedproperties/officenumber"/> 
       </li> 
      </xsl:if> 
     </ul> 
    </xsl:template> 
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
    <xsl:template match="workphone"> 
     <xsl:if test="$office='Chicago'">(773) </xsl:if> 
     <xsl:if test="$office='Orland'">(708) </xsl:if> 
     <xsl:value-of select="."/> 
    </xsl:template> 
</xsl:stylesheet> 

는 출력 : 그러나

<html> 
    <body> 
     <p>Employee 1 Properties</p> 
     <ul> 
      <li id="NameField">Nigro, Brandon L.</li> 
      <li id="DepartmentField">Information Technology</li> 
      <li id="PhoneField">(773) 555-5555</li> 
      <li id="OfficeField">John Academic Center</li> 
     </ul> 
    </body> 
</html> 

, 나는이 사용하는 "변수를 + 경우"접근 방식을 억제하고,를 사용해보십시오 깨끗한 xsl 푸시 스타일 (이 똑같은 결과를 달성) :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="html" indent="yes"/> 
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
    <xsl:template match="Office"> 
     <html> 
      <body> 
       <xsl:apply-templates select="Employee"/> 
      </body> 
     </html> 
    </xsl:template> 
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
    <xsl:template match="Employee"> 
     <p>Employee <xsl:value-of select="@id"/> Properties</p> 
     <ul> 
      <xsl:apply-templates select="hithighlightedproperties/preferredname" mode="li"> 
       <xsl:with-param name="id" select="'NameField'"/> 
      </xsl:apply-templates> 
      <xsl:apply-templates select="hithighlightedproperties/yomidisplayname" mode="li"> 
       <xsl:with-param name="id" select="'DisplayNameField'"/> 
      </xsl:apply-templates> 
      <xsl:apply-templates select="hithighlightedproperties/department" mode="li"> 
       <xsl:with-param name="id" select="'DepartmentField'"/> 
      </xsl:apply-templates> 
      <xsl:apply-templates select="hithighlightedproperties/workphone" mode="li"> 
       <xsl:with-param name="id" select="'PhoneField'"/> 
      </xsl:apply-templates> 
      <xsl:apply-templates select="hithighlightedproperties/officenumber" mode="li"> 
       <xsl:with-param name="id" select="'OfficeField'"/> 
      </xsl:apply-templates> 
     </ul> 
    </xsl:template> 
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
    <xsl:template match="workphone"> 
     <xsl:variable name="office" select="../../../@code"/> 
     <xsl:if test="$office='Chicago'">(773) </xsl:if> 
     <xsl:if test="$office='Orland'">(708) </xsl:if> 
     <xsl:value-of select="."/> 
    </xsl:template> 
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
    <xsl:template match="*[string-length(.)&gt;0]" mode="li"> 
     <xsl:param name="id" select="local-name()"/> 
     <li id="{$id}"> 
      <xsl:apply-templates select="."/> 
     </li> 
    </xsl:template> 
</xsl:stylesheet> 
+0

작동하지 않았습니다. :(코드를 추가 한 후에 변경된 사항이 없습니다.) 템플릿이 동등한 회사 전화 번호와 일치해야하거나이 경우 OfficeField (첫 번째 게시물에 명시된)의 직장 전화 번호와 같아야합니다. 또한 직장 전화가 출력되는 곳에서 위 또는 아래에 배치해야합니까? –

+0

네, 죄송합니다. 어쩌면 정보를 너무 적게 줄 수도 있습니다. 이제 필요한 모든 세부 정보를 제공하는 게시물을 편집하겠습니다. –

+0

인내심에 감사드립니다. 나는 xsl에 HTML이 있다는 것을 몰랐다. 그렇다면이 기능을 테스트하고 싶다. 메모장에 복사하고, 변수를 설정하고, 브라우저에서 여는 것만 큼 간단 할까? –