XSLT½Ì³Ì

XSLT ½éÉÜ
2007-3-30

XSL ÓïÑÔ XSLT ä¯ÀÀÆ÷

XSLT is a language for transforming XML documents into XHTML documents or to other XML documents.
XSLTÊÇÒ»ÖÖ°ÑXMLÎļþת»»³ÉXHTMLÎĵµ»òÕ߯äËûµÄXMLÎĵµµÄÓïÑÔ¡£

XPath is a language for navigating in XML documents.
XPathÊÇÒ»ÖÖÓÉÓÚ²Ù×÷XMLÎĵµµÄÓïÑÔ¡£


What You Should Already Know
ѧǰ»ù´¡

Before you continue you should have a basic understanding of the following:
Èç¹ûÄãÏë¼ÌÐøÏÂÃæµÄѧϰ£¬Äã±ØÐëµÃÕÆÎÕÏÂÃæµÄһЩ»ù±¾³£Ê¶¡£

If you want to study these subjects first, find the tutorials on our Home page.
Èç¹ûÄãÏëÒªÏÈѧϰÕâЩ¿ÎÌ⣬ÄÇÇëÔÚ֪ʶ¿âÕÒµ½ÕâЩ½Ì³Ì.


What is XSLT?
ʲôÊÇXSLT£¿


XSLT = XSL Transformations
XSLT=XSLת»»£¨XSL Transformations£©

XSLT is the most important part of XSL.
XSLTÊÇXSLµÄ×îÖØÒªµÄÒ»²¿·Ö¡£

XSLT is used to transform an XML document into another XML document, or another type of document that is recognized by a browser, like HTML and XHTML. Normally XSLT does this by transforming each XML element into an (X)HTML element.
XSLTÓÃÓÚ°ÑXMLÎļþת»»³ÉÁíÒ»·ÝXMLÎļþ£¬»òÕßת»»³ÉÁíÒ»ÖÖ±»ä¯ÀÀÆ÷Ëùʶ±ðµÄÖîÈçHTMLºÍXHTMLÀàÐ͵ÄÎļþ¡£Í¨³£Çé¿öÏ£¬XSLTÊÇͨ¹ý°Ñÿ¸öXMLÔªËØ×ª»»³É£¨X£©HTMLÎļþÀ´Íê³ÉµÄ¡£

With XSLT you can add/remove elements and attributes to or from the output file. You can also rearrange and sort elements, perform tests and make decisions about which elements to hide and display, and a lot more.
ͨ¹ýXSLT£¬Äã¿ÉÒÔ´ÓÒÑÊä³öµÄÎļþÀïÌí¼Ó/ÒÆ³ýÔªËØºÍÊôÐÔ¡£ÄãÒ²¿ÉÒÔ°ÑÔªËØÖØÐÂÅÅÁкͷÖÀִ࣬ÐвâÊÔÓï¾ä£¬¾ö¶¨ÊÇÒþ²Ø»¹ÊÇÏÔÊ¾ÔªËØ£¬»òÕßʵÏÖÆäËü¸ü¶àµÄ¹¦ÄÜ¡£

A common way to describe the transformation process is to say that XSLT transforms an XML source-tree into an XML result-tree.
¶ÔÓÚÃèÊöת»»¹ý³Ì£¬¿ÉÒÔÐÎÏóµÄÃèÊöΪ£ºXSLT°ÑXMLÔ´Ê÷ת£¨XML source-tree£©»»³ÉXML½á¹ûÊ÷£¨XML result-tree£©¡£


XSLT Uses XPath
XSLT¶ÔÓÚXPathµÄʹÓÃ

XSLT uses XPath to find information in an XML document. XPath is used to navigate through elements and attributes in XML documents.
XSLTͨ¹ý¶ÔXPathµÄʹÓÃÀ´ÕÒѰXMLÎĵµÖеÄÐÅÏ¢¡£XPathÓÃÓÚ²Ù×÷XMLÎļþÖеÄÔªËØºÍÊôÐÔ¡£

If you want to study XPath first, please read our XPath Tutorial.
Èç¹ûÄãÏëÏÈѧϰXPath£¬ÇëÏÈÔĶÁÎÒÃǵÄXPath½Ì³Ì.


How Does it Work?
ÈçºÎʹËüÔËÐУ¿

In the transformation process, XSLT uses XPath to define parts of the source document that should match one or more predefined templates. When a match is found, XSLT will transform the matching part of the source document into the result document.
ÔÚת»»¹ý³ÌÖУ¬XSLTͨ¹ýXPathÀ´¶¨Ò岿·ÖÓ¦¸ÃºÍÒ»¸ö»ò¸ü¶àÔ¤¶¨µÄÄ£°åÏàÆ¥ÅäµÄÔ´Îļþ¡£µ±Ò»¸öÆ¥ÅäÕÒµ½ºó£¬XSLT½«»á°ÑÏàÆ¥ÅäµÄ²¿·ÖÔ´Îļþת»»³É½á¹ûÎĵµ¡£


XSLT is a Web Standard
XSLTÊÇÒ»¸öÍøÂç±ê×¼

XSLT became a W3C Recommendation 16. November 1999.
XSLTÔÚ1999Äê11ÔÂ16ÈÕ³ÉΪW3C²Î¿¼±ê×¼¡£

 

XSL ÓïÑÔ XSLT ä¯ÀÀÆ÷