두 번째 값을 사용하여 첫 번째 루프에 정의 된 다른 신자 내부의 각 내부 및 액세스 속성에 액세스하십시오.

StackOverflow https://stackoverflow.com/questions/1200936

  •  05-07-2019
  •  | 
  •  

문제

헤더 모음의 각 항목 모음에서 특정 속성을 찾으십시오. 내가 같은 것이 있다면 :

<ROOT>  
  <Listings> 
    <Listing>
      <Headers>
        <Header width="3cm" value="UserName" />
        <Header width="3cm" value="MobileAlias" />
        <Header width="3cm" value="Name" />
        <Header width="3cm" value="Email" />
        <Header width="1cm" value="Gender" />
        <Header width="2cm" value="LastLoginDate" />
        <Header width="2cm" value="LastActivityDate" />
        <Header width="1.5cm" value="IsApproved" />
        <Header width="1.5cm" value="IsLockedOut" />
      </Headers>
      <Footers></Footers>
      <Items>
        <Item UserName="Admin" MobileAlias="Admin" Name="Systems Administrator" Email="388354123@foo.com" Gender="Male" LastLoginDate="29-07-2009 12:54:59" LastActivityDate="29-07-2009 12:56:37" IsApproved="True" IsLockedOut="False" />
        <Item UserName="Guest" MobileAlias="Guest" Name="Anonymous User" Email="1516626590@foo.com" Gender="Male" LastLoginDate="" LastActivityDate="" IsApproved="True" IsLockedOut="False" />
      </Items>
    </Listing>
  </Listings>
</ROOT>

어떻게 얻을 수 있습니까?

  <fo:table-row>
    <fo:table-cell><fo:block>Admin</fo:block></fo:table-cell>
    <fo:table-cell><fo:block>Admin</fo:block></fo:table-cell>
    <fo:table-cell><fo:block>System Administrator</fo:block></fo:table-cell>
    <fo:table-cell><fo:block>388354123@foo.com</fo:block></fo:table-cell>
    <fo:table-cell><fo:block>Male</fo:block></fo:table-cell>
    <fo:table-cell><fo:block>29-07-2009 12:54:59</fo:block></fo:table-cell>
    <fo:table-cell><fo:block>29-07-2009 12:56:37</fo:block></fo:table-cell>
    <fo:table-cell><fo:block>True</fo:block></fo:table-cell>
    <fo:table-cell><fo:block>True</fo:block></fo:table-cell>
  </fo:table-row>
  (...)

내 말은, 항목의 각 항목, 헤더의 각 헤더, 항목에서 속성 헤더@value를 반환합니다.

매우 감사.

도움이 되었습니까?

해결책

유지 관리 가능성을 높이기 위해 별도의 템플릿을 사용하는 것이 좋습니다. 다음은 기본적으로 Anthonywjones가 한 일이지만 입력에 적합합니다.

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
>

  <xsl:output method='xml' indent="yes" /> 

  <!-- <Listing> elements become tables -->
  <xsl:template match="Listing">
    <fo:table>
      <xsl:apply-templates />
    </fo:table>
  </xsl:template>

  <!-- <Items> elements become table rows -->
  <xsl:template match="Items">
    <fo:table-row>
      <xsl:apply-templates />
    </fo:table-row>
  </xsl:template>

  <!-- applies the correct order to the output -->
  <xsl:template match="Item">
    <fo:table-row>
      <xsl:variable name="this" select="." />
      <xsl:for-each select="../../Headers/Header">
        <xsl:apply-templates select="$this/@*[name() = current()/@value]" />
      </xsl:for-each>
    </fo:table-row>
  </xsl:template>

  <!-- <Item> attributes become table cells -->
  <xsl:template match="Item/@*">
    <fo:table-cell>
      <fo:block>
        <xsl:value-of select="." />
      </fo:block>
    </fo:table-cell>
  </xsl:template>

  <xsl:template match="text()" />

</xsl:stylesheet>

다른 팁

나는 xsl-fo를 모르지만 그것은 관련이 없습니다. 다음은 HTML 테이블을 생성하는 간단한 예입니다.

<xsl:template match="/ROOT">
  <table rules="all">
    <xsl:for-each select="Listings/Listing/Items/Item">
      <xsl:variable name="item" select="." /> 
      <tr>
        <xsl:for-each select="/ROOT/Listings/Listing/Headers/Header">
          <td><xsl:value-of select="$item/@*[local-name()=current()/@value]" /></td>
        </xsl:for-each>
      </tr>
    </xsl:for-each>
  </table>
</xsl:template>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top