dude
Guest
Как заставить XSLT-процессор обработать XML-документ повторно ...
Добрый день! Подскажите как лучше сделать, очень надо.
Есть такой XML-файл:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="document.xsl"?>
<document title="XML in PHP 5 - What's New?" url="docs/xml-php.xml">
<authors>
<author>Christian Stocker</author>
<author>Leha</author>
<author>Christian Stocker</author>
<author>Leha</author>
</authors>
<pubdate>March 18, 2004</pubdate>
<chapter id="1" title="Intended Audience">
<text>This article is intended for PHP developers at all levels who are interested in using the new XML functionality in PHP 5. Only basic, general knowledge about XML is assumed. However, it's an advantage if you have already worked with XML in PHP. </text>
</chapter>
<chapter id="2" title="Introduction">
<text>In today's Internet world, XML isn't just a buzzword anymore, but a widely accepted and used standard. Therefore XML support was taken more seriously for PHP 5 than it was in PHP 4. In PHP 4 you were almost always faced with non-standard, API-breaking, memory leaking, incomplete functionality. Although some of these deficiencies were dealt with in the 4.3 series of PHP 4, the developers nevertheless decided to dump almost everything and start from scratch in PHP 5. </text>
</chapter>
<chapter id="3" title="XML in PHP 4">
</chapter>
<chapter id="4" title="XML in PHP 5">
<chapter id="5" title="Streams support">
</chapter>
</chapter>
<chapter id="6" title="SAX">
</chapter>
<chapter id="7" title="DOM">
<chapter id="8" title="Reading the DOM">
</chapter>
<chapter id="9" title="XPath">
</chapter>
<chapter id="10" title="Writing to the DOM">
</chapter>
<chapter id="11" title="Extending Classes">
</chapter>
<chapter id="12" title="HTML">
</chapter>
</chapter>
<chapter id="13" title="Validation">
</chapter>
<chapter id="14" title="SimpleXML">
<chapter id="15" title="Writing to SimpleXML Documents">
</chapter>
<chapter id="16" title="Interoperability">
</chapter>
</chapter>
<chapter id="17" title="XSLT">
<chapter id="18" title="Calling PHP Functions">
</chapter>
</chapter>
<chapter id="19" title="Summary">
</chapter>
<chapter id="20" title="Links">
<chapter id="21" title="PHP 4 Specific">
</chapter>
<chapter id="22" title="PHP 5 Specific">
</chapter>
<chapter id="23" title="Standards">
</chapter>
<chapter id="24" title="Tools">
</chapter>
</chapter>
<chapter id="25" title="About the Author">
</chapter>
</document>
Для него написал XSL-трансформацию:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<!-- Шапка документа -->
<html>
<head>
<LINK href="style.css" rel="stylesheet" type="text/css"/>
<title>
<xsl:apply-templates select="document/@title"/>
</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="document">
<h3><xsl:value-of select="@title"/></h3>
<!-- Выводим список авторов статьи -->
<p><b>By
<xsl:for-each select="//authors/author">
<font color="#003333"><xsl:value-of select="."/></font>
<!-- Если автор в списке последний, запятую не выводим -->
<xsl:if test="not (position()=last())">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
</b></p>
<xsl:apply-templates select="//chapter"/>
</xsl:template>
<xsl:template match="chapter">
<a href="#{@id}"><xsl:value-of select="@title"/></a><br/>
</xsl:template>
<xsl:template match="chapter/chapter">
* <a href="#{@id}"><xsl:value-of select="@title"/></a><br/>
</xsl:template>
</xsl:stylesheet>
Эта трансформация выводит на экран такую вещь:
XML in PHP 5 - What's New?
By Christian Stocker, Leha, Christian Stocker, Leha
Intended Audience
Introduction
XML in PHP 4
XML in PHP 5
* Streams support
SAX
DOM
* Reading the DOM
* XPath
* Writing to the DOM
* Extending Classes
* HTML
Validation
SimpleXML
* Writing to SimpleXML Documents
* Interoperability
XSLT
* Calling PHP Functions
Summary
Links
* PHP 4 Specific
* PHP 5 Specific
* Standards
* Tools
About the Author
Мне же надо чтобы после вывода содержания выводились все главы статьи под содержанием. Т.е. в XSLT-файле мне нужно написать еще один шаблон, но как его составить ума не приложу. XML начал изучать 3 дня назад по необходимости.
Помогите, пожалуйста!!!! Очень надо!!!
Добрый день! Подскажите как лучше сделать, очень надо.
Есть такой XML-файл:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="document.xsl"?>
<document title="XML in PHP 5 - What's New?" url="docs/xml-php.xml">
<authors>
<author>Christian Stocker</author>
<author>Leha</author>
<author>Christian Stocker</author>
<author>Leha</author>
</authors>
<pubdate>March 18, 2004</pubdate>
<chapter id="1" title="Intended Audience">
<text>This article is intended for PHP developers at all levels who are interested in using the new XML functionality in PHP 5. Only basic, general knowledge about XML is assumed. However, it's an advantage if you have already worked with XML in PHP. </text>
</chapter>
<chapter id="2" title="Introduction">
<text>In today's Internet world, XML isn't just a buzzword anymore, but a widely accepted and used standard. Therefore XML support was taken more seriously for PHP 5 than it was in PHP 4. In PHP 4 you were almost always faced with non-standard, API-breaking, memory leaking, incomplete functionality. Although some of these deficiencies were dealt with in the 4.3 series of PHP 4, the developers nevertheless decided to dump almost everything and start from scratch in PHP 5. </text>
</chapter>
<chapter id="3" title="XML in PHP 4">
</chapter>
<chapter id="4" title="XML in PHP 5">
<chapter id="5" title="Streams support">
</chapter>
</chapter>
<chapter id="6" title="SAX">
</chapter>
<chapter id="7" title="DOM">
<chapter id="8" title="Reading the DOM">
</chapter>
<chapter id="9" title="XPath">
</chapter>
<chapter id="10" title="Writing to the DOM">
</chapter>
<chapter id="11" title="Extending Classes">
</chapter>
<chapter id="12" title="HTML">
</chapter>
</chapter>
<chapter id="13" title="Validation">
</chapter>
<chapter id="14" title="SimpleXML">
<chapter id="15" title="Writing to SimpleXML Documents">
</chapter>
<chapter id="16" title="Interoperability">
</chapter>
</chapter>
<chapter id="17" title="XSLT">
<chapter id="18" title="Calling PHP Functions">
</chapter>
</chapter>
<chapter id="19" title="Summary">
</chapter>
<chapter id="20" title="Links">
<chapter id="21" title="PHP 4 Specific">
</chapter>
<chapter id="22" title="PHP 5 Specific">
</chapter>
<chapter id="23" title="Standards">
</chapter>
<chapter id="24" title="Tools">
</chapter>
</chapter>
<chapter id="25" title="About the Author">
</chapter>
</document>
Для него написал XSL-трансформацию:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<!-- Шапка документа -->
<html>
<head>
<LINK href="style.css" rel="stylesheet" type="text/css"/>
<title>
<xsl:apply-templates select="document/@title"/>
</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="document">
<h3><xsl:value-of select="@title"/></h3>
<!-- Выводим список авторов статьи -->
<p><b>By
<xsl:for-each select="//authors/author">
<font color="#003333"><xsl:value-of select="."/></font>
<!-- Если автор в списке последний, запятую не выводим -->
<xsl:if test="not (position()=last())">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
</b></p>
<xsl:apply-templates select="//chapter"/>
</xsl:template>
<xsl:template match="chapter">
<a href="#{@id}"><xsl:value-of select="@title"/></a><br/>
</xsl:template>
<xsl:template match="chapter/chapter">
* <a href="#{@id}"><xsl:value-of select="@title"/></a><br/>
</xsl:template>
</xsl:stylesheet>
Эта трансформация выводит на экран такую вещь:
XML in PHP 5 - What's New?
By Christian Stocker, Leha, Christian Stocker, Leha
Intended Audience
Introduction
XML in PHP 4
XML in PHP 5
* Streams support
SAX
DOM
* Reading the DOM
* XPath
* Writing to the DOM
* Extending Classes
* HTML
Validation
SimpleXML
* Writing to SimpleXML Documents
* Interoperability
XSLT
* Calling PHP Functions
Summary
Links
* PHP 4 Specific
* PHP 5 Specific
* Standards
* Tools
About the Author
Мне же надо чтобы после вывода содержания выводились все главы статьи под содержанием. Т.е. в XSLT-файле мне нужно написать еще один шаблон, но как его составить ума не приложу. XML начал изучать 3 дня назад по необходимости.
Помогите, пожалуйста!!!! Очень надо!!!