Pipeline HOW TO: ??????? XSLT ?? ??????? .NET

?????? ????????? ?????? ?????????
???? ???????: 320847 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ?????? ????? pipeline ??????? XSL Transformation (XSLT) ?? ????????? .NET. ??????? "Pipelining" ?? ???? ??????? XSLT ? ?? ????? ???? ?????? ?? ???????? ?? ????? ??? ????? ??????? (XML) ???? ??????? ?????? ????? ????? ?? ???? ?? XSLT ?????? ??????? ??????? ???????? ???? ???????. ????? ???????, ??? ??????? ??????? ???? ?? ?????? ?????? ??? ????? ?????? ?? ?? ???????? ????? ??????? ??? ??????? ??????? ??????? ???? ??????? ??????? ???? ??????? ??????? ???? ???? ??????? ???? ?????.

???? ??????? ?????? .NET Framework ?? System.Xml.XslSystem.Xml.XPath ? ?????? ??????? System.IO ??????? pipeline ??????? XSLT ?? ??????? .NET. ???? ??????? ??????? ?? ??? ??????? ??????? ???????? ?? ????? ??????? ????? pipelining ??????? XSLT ?? ??? ??????? ASP.NET. ??????? ??????? ???? ????? ????? ????????? ?? ????? ???? ?? ????????? .NET ???? pipeline ??????? XSLT.

????? ?? ????? ????? ASP.NET ?????

  1. ??????? Visual Studio .NET ?????? ????? Visual Basic Microsoft .NET ????? ??? ASP.NET ???? ???? "XSLTPipelineDemo" (???? ?????? ????????).
  2. ??????? ????????? ???????? ??????? ?????? ????? XML ???? "Employees.xml" (???? ?????? ????????) ??? ??????? ??????:
    <?xml version='1.0'?>
    <employees>
      <employee>
        <employeeId>1</employeeId>
        <name>
          <given>Nancy</given>
          <family>Davolio</family>
        </name>
      </employee>
      <employee>
        <employeeId>2</employeeId>
        <name>
          <given>Andrew</given>
          <family>Fuller</family>
        </name>
      </employee>
      <employee>
        <employeeId>3</employeeId>
        <name>
          <given>Janet</given>
          <family>Leverling</family>
        </name>
      </employee>  
    </employees>
    					
  3. ??????? ????????? ???????? ??????? ?????? ?????? ???? ????? XSLT ???? ???? "sortEmployees.xslt" (???? ?????? ????????) ??? ???????. ????? ??? ???? ????? ??? ????????? ???????? XSLT ???? ???????? ?? ????? XML Employees.xml (?????? ?????? ??? ??? ??????? [?????? ??? ????????] ??????). ??????? ???? ?? ?????? ??? ????? ???? ????? ??? ????? ?? ????? ?? ???? ?????? XML:
    <?xml version='1.0'?>
    
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <xsl:param name="sortColumn" select="'family'"/>
    <xsl:param name="sortOrder" select="'descending'"/>
    
    
    <xsl:template match="employees">
       <employees>
    
       <xsl:apply-templates select="employee/name">  
           <xsl:sort select="./*[local-name() = $sortColumn]" order="{$sortOrder}"/>            
       </xsl:apply-templates>  
    
       </employees>
    </xsl:template> 
    
    <xsl:template match="employee/name">
      <employee>
    	  <xsl:copy-of select="parent::node()/*"/>
      </employee>  
    </xsl:template> 
    
    </xsl:stylesheet>
    					
  4. ??????? ????????? ???????? ??????? ?????? ?????? ???? ????? XSLT ???? "EmployeesHTMLTable.xslt" (???? ?????? ????????) ?? ???????. ????? ??? ???? ????? ??? ????????? ???????? XSLT ?????? ?????? XML ?????? (??????? ?? ????? XML Employees.xml ?? ????? XML ???? ?? ?????? ??? ????? ???? ????? XSLT sortEmployees.xsl ??? ????? XML Employees.xml) ?????? ??? ???? ??? ????? ???? ????? (HTML):
    <?xml version='1.0'?>
    
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <xsl:template match="employees">
    	<HTML>
    	<BODY>
    	<TABLE BORDER="1">
    	<TR>
    	  <TH>Employee ID</TH>
    	  <TH>Employee Name</TH>
    	</TR>
    
    	<xsl:for-each select="employee">
    		<TR>
      		  <TD>
    		     <xsl:value-of select="employeeId"/>
    		  </TD>
    		  <TD>
    		     <xsl:value-of select="name/family"/>, <xsl:value-of select="name/given"/>
    		  </TD>
    		</TR>
    	</xsl:for-each>
    
    	</TABLE>
    	</BODY>
    	</HTML>   
    </xsl:template> 
    
    </xsl:stylesheet>
    
    					
  5. ????? ????? ?? ?? ????? XSLT ???? ????? ?? ????? ??? ??? Employees.xml. ????? sortEmployees.xsl ??? ???????? ???????? ?? ??? Employees.xml ????? ????? employeesHTMLTable.xsl ?????? ????? ???? HTML ???? XML. ?????? ??? ????? ???? HTML ??? ???????? ?????? ?? ????? ?????? ??? ??? ???????, pipeline ??? ??????? XSLT ????? (????? ?????? sortEmployees.xsl ??? ??? Employees.xml ?? ?? ?????? employeesHTMLTable.xsl ??? ??????? ???? ?? ??????? ?????? ??????? ?????).
  6. ??? ???? ???????? ???????? ??????? ?? ????? ????? Page_LoadWebForm1.aspx ?????? pipelining ?? ???? ??????:
    'Load the source XML document (Employees.xml) into an XPathDocument object.
    
    Dim xmlDoc As New System.Xml.XPath.XPathDocument(Server.MapPath("employees.xml"))
    
    'Load the first stylesheet (sortEmployees.xslt) that sorts the data in employees.xml
    'into an XslTransform object.
    
    Dim xslt As New System.Xml.Xsl.XslTransform()
    xslt.Load(Server.MapPath("sortEmployees.xslt"))
    
    'Execute the first transformation and write the interim output (the sorted XML)
    'to a MemoryStream object. Using an in memory stream (as opposed to a FileStream object) 
    'to store the interim output generated by the first transformation is a better option from  
    'a performance standpoint as it avoids unnecessary disk I/O.
    
    Dim memStream As New System.IO.MemoryStream()
    xslt.Transform(xmlDoc, Nothing, memStream)
    
    'Reset the MemoryStream internal pointer to point to the 
    'beginning of the stream. This is required for the following line of 
    'code to be able to read the data from the memory stream.
    
    memStream.Position = 0
    
    'Load the interim sorted XML output in an XPathDocument object. 
    'Notice that a second XPathDocument object is created to do this. 'The reason for this is that the XPathDocument class does not implement a Load 'method (like the System.Xml.XmlDocument class) that can be used to re-load new XML data into an existing 
    'object instance. While a single XmlDocument object could have been used to execute the two pipelined 'transformations in this sample, it has not been chosen because the XPathDocument is highly optimized for XPath query 
    'execution and XSLT transformations. It is the recommended interface to use when programatically executing 
    'XSLT transformations in .NET applications.
    
    Dim interimDoc As New System.Xml.XPath.XPathDocument(memStream)
    
    'Load the second stylesheet(employeesHTMLTable.xslt)that transforms the sorted data to an HTML table
    'into the XslTransform object.
    
    xslt.Load(Server.MapPath("employeesHTMLTable.xslt"))
    
    'Execute the second transformation and stream the output directly to the 
    'ASP.Net Response object's OutputStream to display the results in the client browser.
    
    xslt.Transform(interimDoc, Nothing, Response.OutputStream)
    					
  7. ???? ???? ????.

?????? ??????? ASP.NET ?????

  1. ????? ??????? ASP.NET XSLTPiplelineDemo ??? ???? ??????? ?? ???? WebForm1.aspx ?? ????????.
  2. ??? ????? ??????? XSLT ????????? ???????? ?? ????? ????? Page_LoadWebForm1.aspx ????? ?????? ??????? ?? ????? ???? HTML ???? ???? ????? (?????? ?????? ???????? ??? ??? ???????) ??? ????????.
  3. ????? ???? ???????? ??? ????? ??????? ASP.NET.

???????

???? ???????: 320847 - ????? ??? ??????: 07/???/1424 - ??????: 3.2
????? ???
  • Microsoft .NET Framework 1.0
  • Microsoft .NET Framework 1.1
????? ??????: 
kbmt kbbcl kbhowtomaster KB320847 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????320847

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com