문제

"언제"와 "그렇지 않으면"을 태그로 감싸는 방법은 무엇입니까?

아래의 예에서 나는 div를 추가하려고 시도했지만 각 결과를 래핑하게됩니다.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" version="1.0">
   <xsl:output method="xml" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" encoding="UTF-8" />
   <xsl:include href="vcardbook.xsl" />
   <xsl:template name="entriesLoopBook">
      <div id="team-posts">
         <xsl:for-each select="entries/entry ">
            <div>
               <xsl:choose>
                  <xsl:when test="$fid != 887">
                     <div class="physical">
                        <xsl:call-template name="vcardbook" />
                     </div>
                  </xsl:when>
                  <xsl:otherwise>
                     <div class="service">
                        <xsl:call-template name="vcardbook" />
                     </div>
                  </xsl:otherwise>
               </xsl:choose>
            </div>
         </xsl:for-each>
      </div>
      <div style="clear:both;" />
   </xsl:template>
</xsl:stylesheet>

위의 코드에서 결과 :

<div>
   <div class="physical"><div class="567"></div></div>
   <div class="physical"><div class="457"></div></div>
   <div class="physical"><div class="342"></div></div>
   <div  class="service"><div class="887"></div></div>
   <div  class="service"><div class="887"></div></div>
</div>

내가보고 싶은 방법 :

<div>
   <div class="physical">
      <div class="567"></div>
      <div class="457"></div>
      <div class="342"></div>
   </div>
   <div  class="service">
     <div class="887"></div>
     <div class="887"></div>
   </div>
</div>

도와 주셔서 감사합니다.

도움이 되었습니까?

해결책

내가 지배 할 때 나는 사용하지 않는 것이 좋습니다 for-each, 그러나 가능한 한 코드를 거의 변경하려면 다음을 시도하십시오.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" version="1.0">
   <xsl:output method="xml" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" encoding="UTF-8" />
   <xsl:include href="vcardbook.xsl" />
   <xsl:template name="entriesLoopBook">
      <div id="team-posts">
         <div>
            <div class="physical">
              <xsl:for-each select="entries/entry[<wherever you get $fid from> != 887">
                <xsl:call-template name="vcardbook"/>
              </xsl:for-each>
            </div>
            <div class="service">
              <xsl:for-each select="entries/entry[<wherever you get $fid from> = 887">
                <xsl:call-template name="vcardbook"/>
              </xsl:for-each>
            </div>
         </dv>
      </div>
      <div style="clear:both;" />
   </xsl:template>
</xsl:stylesheet>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top