background preloader

XSL

Facebook Twitter

S Blog » Blog Archive » XPath in SimpleXML. SimpleXML as it name imply, is a very simple API to traverse XML implemented specially in PHP language. It is very similar to the XPath, but since it has more PHP friendly syntax PHP developers really like to use it. As an Example for this XML: <dwml><data><location><location-key>point1</location-key><point latitude="37.39" longitude="-122.07"></point></location></data> .....

</dwml> XPATH Query to take the latitude in more general way /dwml/data/location/point/@latitude Where as with simple XML it is just a familiar PHP statement, $simplexml->data->location->point->attributes()->latitude Anyway still you can use the xpath inside your simplexml code. $simplexml= new SimpleXMLElement($xml); $lats = $simplexml->xpath('/dwml/data/location/point/@latitude'); echo $lats[0]; This simplicity allows you to choose between these two methods interchangeably as best fit per your application.

Ability to use of XPath shorthand Take the above example XML it self. //@latitude //mynode //mynode[last()] Tip: Control white space in an XSLT style sheet. Note: For this tip, you can use any XSLT processor, such as Xalan or Saxon, or a browser-based solution, such as Microsoft Internet Explorer or Mozilla. White space stripping rules Before processing a transformation, an XSLT processor analyzes the style sheet and the source document, and removes any applicable white space nodes. It then processes the document, building the result tree from the remaining nodes. Let's look at a basic transformation. The source document contains raw FAQ information that will be translated into a different XML structure for processing by a second application: Listing 1. <? The style sheet for this transformation is intended to combine individual lines, but will ultimately have to preserve the white space in the code section: Listing 2.

Transforming the document shows the results of the default rules for white space stripping: Listing 3. <? Back to top Controlling white space in the source Listing 4. <? Listing 5. <? Listing 6. <? Listing 7. <? Listing 8. ... ... <? XPath, XQuery, and XSLT Function Reference. Einstieg in XSLT (Einführung in XML/XSLT) Kommentare Kommentare werden in XSLT geschrieben als Diese Kommentare werden i.d.R. nicht in die Ausgabe übernommen, möchten Sie (z.b. für eine leichtere lesbarkeit) Kommentare in den erzeugten HTML-Text schreiben, müssen Sie die Kommentare in ein xsl:comment-tag einbetten. xsl:text Der gesamte Text in der XSL-Datei, der ausgegeben werden soll, müsste streng genommen in xsl:text - Tags stehen.

Genaugenommen wird er aber auch ausgegeben, wenn er nicht in diesen Tags steht. xsl:template *name Ein Template (zu deutsch: Vorlage) ist das zentrale Element in XSLT: dort werden alle Tagumwandlungen und Positionierungen vorgenommen. --- datei xslt1.xml <? Daraus können Sie z.B. mit "saxon -a -o xslt1.html xslt1.xml" eine HTML-Datei erstellen wenn Sie Instant Saxon benutzen. Apply-Templates ohne passende Templates Hallo <b>Welt</b>! Ein anderes Tag matchen Achten Sie immer darauf, in der XML-Datei die gewünschte XSL-Datei anzupassen. Xsl:value-of select Neben der schon erwähnten Methode xsl:apply-updates. XSLT Reference. XSLT Tryit Editor v1.0.