0

我第一次使用 XSLT,终于让它工作了;但我不想在最终输入中显示所有 XML 数据...我只想查看 XSLT 样式表中的表中的内容。任何人都可以帮助建议我如何将输出限制在这个范围内吗?

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<?mso-infoPathSolution name="urn:schemas-microsoft-com:office:infopath:QBA--Quote-Below-Authority:-myXSD-2012-12-05T14-55-38" solutionVersion="1.0.0.492" productVersion="14.0.0.0" PIVersion="1.0.0.0" href="http://team.apmoller.net/sites/NNP-One-Stop-Shop/QBA%20Quote%20Below%20Authority/Forms/template.xsn"?>
<?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.3"?>
<my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls" xmlns:ma="http://schemas.microsoft.com/office/2009/metadata/properties/metaAttributes" xmlns:d="http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields" xmlns:q="http://schemas.microsoft.com/office/infopath/2009/WSSList/queryFields" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:dms="http://schemas.microsoft.com/office/2009/documentManagement/types" xmlns:tns="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService" xmlns:s1="http://microsoft.com/wsdl/types/" xmlns:ns1="http://schemas.microsoft.com/sharepoint/soap/directory/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:ns2="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-12-05T14:55:38" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-US">
    <my:Requestor>VRO009</my:Requestor>
    <my:DecisionMaker>0</my:DecisionMaker>
    <my:QBARateStructure></my:QBARateStructure>
    <my:ClusterReviewer></my:ClusterReviewer>
    <my:ClusterReviewDate xsi:nil="true"></my:ClusterReviewDate>
    <my:QBA-Request-Table>
        <my:QBA-Request>
            <my:Origin>zeebrugge</my:Origin>
            <my:Destination>chennai</my:Destination>
            <my:EquType>Dry</my:EquType>
            <my:EquSize>20</my:EquSize>
            <my:Weight>22</my:Weight>
            <my:TargetWeeklyVolume>10</my:TargetWeeklyVolume>
            <my:CommitmentReqd>No</my:CommitmentReqd>
            <my:CurrentAllin>1000</my:CurrentAllin>
            <my:RequestedAllin>125</my:RequestedAllin>
            <my:RequestedCY>1310</my:RequestedCY>
            <my:CompetitionAllin>125</my:CompetitionAllin>
            <my:CentreTNMLineAction></my:CentreTNMLineAction>
            <my:CentreTNMLineCounter></my:CentreTNMLineCounter>
        </my:QBA-Request>
        <my:QBA-Request>
            <my:Origin>zeebrugge</my:Origin>
            <my:Destination>chennai</my:Destination>
            <my:EquType>Dry</my:EquType>
            <my:EquSize>20</my:EquSize>
            <my:Weight>22</my:Weight>
            <my:TargetWeeklyVolume>10</my:TargetWeeklyVolume>
            <my:CommitmentReqd>No</my:CommitmentReqd>
            <my:CurrentAllin>1000</my:CurrentAllin>
            <my:RequestedAllin>125</my:RequestedAllin>
            <my:RequestedCY>1310</my:RequestedCY>
            <my:CompetitionAllin>125</my:CompetitionAllin>
            <my:CentreTNMLineAction></my:CentreTNMLineAction>
            <my:CentreTNMLineCounter></my:CentreTNMLineCounter>
        </my:QBA-Request>
        <my:QBA-Request>
            <my:Origin>zeebrugge</my:Origin>
            <my:Destination>chennai</my:Destination>
            <my:EquType>Dry</my:EquType>
            <my:EquSize>20</my:EquSize>
            <my:Weight>22</my:Weight>
            <my:TargetWeeklyVolume>10</my:TargetWeeklyVolume>
            <my:CommitmentReqd>No</my:CommitmentReqd>
            <my:CurrentAllin>1000</my:CurrentAllin>
            <my:RequestedAllin>125</my:RequestedAllin>
            <my:RequestedCY>1310</my:RequestedCY>
            <my:CompetitionAllin>125</my:CompetitionAllin>
            <my:CentreTNMLineAction></my:CentreTNMLineAction>
            <my:CentreTNMLineCounter></my:CentreTNMLineCounter>
        </my:QBA-Request>
    </my:QBA-Request-Table>
    <my:FormCountry>Belgium</my:FormCountry>
    <my:AccessLevel>Cluster</my:AccessLevel>
    <my:CentreReviewer></my:CentreReviewer>
    <my:CentreReviewDate xsi:nil="true"></my:CentreReviewDate>
    <my:group1></my:group1>
    <my:Filename>QBA2013-06-06T13:59:18VRO009</my:Filename>
    <my:Engine>New</my:Engine>
</my:myFields>

这是我的 XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-12-05T14:55:38">
<xsl:template match="my:myFields/my:QBA-Request-Table">
    <h2>Request Lines</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Origin</th>
        <th>Destination</th>
      </tr>
      <xsl:for-each select="my:QBA-Request">
      <tr>
        <td><xsl:value-of select="my:Origin" /></td>
        <td><xsl:value-of select="my:Destination" /></td>
      </tr>
      </xsl:for-each>
    </table>
</xsl:template>
</xsl:stylesheet>
moijoNoBCOT1T2E2001-01-01231789朝鲜蓟,非冷冻,蔬菜Boeger,AndrewCRB\abo055用户
**请求行   
始发地
1 2
1 3
1 4** ***(粗体字全部按照表格很好地格式化)***
*AllClusterabo0550QBA2013-06-06T15:43:21abo055NewCRB\ABO055trueMaersk LineiojYesiojj警告:您选择了“测试”交易,该交易仅用于形式测试。如果您保持原样,CENTNM 中的任何人都不会审查您的请求。true
4

1 回答 1

0

内置模板将处理除您专门匹配的元素之外的所有元素,因此您需要为根节点编写模板并控制一切。

此外,最好for-each尽可能用模板替换,如果您my从输出中排除不需要的名称空间前缀,并指定带有缩进的 HTML 输出,它会大大整理您的输出。

此样式表演示

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-12-05T14:55:38"
    exclude-result-prefixes="my">

  <xsl:output method="html" indent="yes"/>

  <xsl:template match="/">
    <xsl:apply-templates select="my:myFields/my:QBA-Request-Table"/>
  </xsl:template>

  <xsl:template match="my:QBA-Request-Table">
    <h2>Request Lines</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Origin</th>
        <th>Destination</th>
      </tr>
      <xsl:apply-templates select="my:QBA-Request"/> 
    </table>
  </xsl:template>

  <xsl:template match="my:QBA-Request">
    <tr>
      <td><xsl:value-of select="my:Origin" /></td>
      <td><xsl:value-of select="my:Destination" /></td>
    </tr>
  </xsl:template>

</xsl:stylesheet>

输出

<h2>Request Lines</h2>
<table border="1">
   <tr bgcolor="#9acd32">
      <th>Origin</th>
      <th>Destination</th>
   </tr>
   <tr>
      <td>zeebrugge</td>
      <td>chennai</td>
   </tr>
   <tr>
      <td>zeebrugge</td>
      <td>chennai</td>
   </tr>
   <tr>
      <td>zeebrugge</td>
      <td>chennai</td>
   </tr>
</table>
于 2013-06-06T14:09:21.200 回答