我第一次使用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-01231789Artichokes, non-frozen, vegetablesBoeger, AndrewCRB\abo055User **Request Lines Origin Destination 1 2 1 3 1 4** ***(this in bold is all formatted as per the table nicely)*** *AllClusterabo0550QBA2013-06-06T15:43:21abo055NewCRB\ABO055trueMaersk LineiojYesiojjWARNING: You have selected the "Test" trade, which is meant for form testing only. If you leave this as-is, no one in CENTNM will ever review your request.true
答案 0 :(得分:0)
Built-in templates将处理除您专门匹配的元素之外的所有元素,因此您需要为根节点编写模板并控制所有内容。
此外,最好尽可能使用模板替换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>