0

我想以盒子顺序将盒子和文件夹元素作为兄弟姐妹放在 3 列中。

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="BoxFldr.xsl" ?>
    <ListOfBipBoxfldrlbls>
      <Batch>   
        <ListOfFolder>
          <Folder>
            <FolderNum>Fldr1</FolderNum>             
            <BoxNumber>Box1</BoxNumber>
            <BatchNumber>Batch</BatchNumber>
          </Folder>
          <Folder>
            <FolderNum>Fldr2</FolderNum>       
            <BoxNumber>Box1</BoxNumber>  
            <BatchNumber>Batch</BatchNumber>        
          </Folder>
          <Folder>
            <FolderNum>Fldr3</FolderNum>        
            <BoxNumber>Box1</BoxNumber> 
            <BatchNumber>Batch</BatchNumber>
          </Folder>
          <Folder>
            <FolderNum>Fldr1</FolderNum>
            <BoxNumber>Box2</BoxNumber>
            <BatchNumber>Batch</BatchNumber>
          </Folder>
          <Folder>
            <FolderNum>Fldr2</FolderNum>
            <BoxNumber>Box2</BoxNumber>
            <BatchNumber>Batch</BatchNumber>
          </Folder>
          <Folder>
            <FolderNum>Fldr3</FolderNum>
            <BoxNumber>Box2</BoxNumber>
            <BatchNumber>Batch</BatchNumber>
          </Folder>
          <Folder>
            <FolderNum>Fldr4</FolderNum>
            <BoxNumber>Box2</BoxNumber>
            <BatchNumber>Batch</BatchNumber>
          </Folder>
          </ListOfFolder>
        <ListOfBox>
          <Box>
            <BatchNumber>Batch</BatchNumber>
            <BoxNumber>Box1</BoxNumber>               
          </Box>
          <Box>     
            <BatchNumber>Batch</BatchNumber>
            <BoxNumber>Box2</BoxNumber>                
          </Box>
        </ListOfBox>
      </Batch>  
    </ListOfBipBoxfldrlbls>

我可以使用以下代码将所有文件夹打印为兄弟姐妹

  <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="ListOfBipBoxfldrlbls/Batch/ListOfFolder | ListOfBipBoxfldrlbls/Batch/ListOfBox" > 
        <xsl:variable name="columns" select="3" />
        <TABLE border="1">
          <xsl:for-each select="Folder[position() mod $columns = 1]"> 
             <TR>
               <xsl:for-each select=".|following-sibling::Folder[position() &lt; $columns]">
                 <TD>
                   <xsl:value-of select="FolderNum" />
                   <xsl:value-of select="BoxNumber" />
                 </TD>
               </xsl:for-each> 
             </TR> 
          </xsl:for-each> 
        </TABLE> 
      </xsl:template> 
    </xsl:stylesheet>

我可以得到

 Box1 Fldr1       Box1 Fldr2     Box1 Fldr3

 Box2 Fldr1       Box2 Fldr2    Box2 Fldr3

 Box2 Fldr4

但我无法将 Box 和 Folders 作为兄弟姐妹。

预期输出:

 Box1                     Box1 Fldr1       Box1 Fldr2

 Box1 Fldr3              Box2              Box2 Fldr1

 Box2 Fldr2              Box2 Fldr3        Box2 Fldr4

有人可以帮忙吗。提前致谢。

4

0 回答 0