XSLT (PHP 4) Funktioner

Indholdsfortegnelse

add a note add a note

User Contributed Notes 9 notes

up
0
hentaidream at gmx dot de
12 years ago
How to make a XSLT Side with function

<code>
<xsl:output method="xhtml"/>
  <xsl:template match="/">
    <html>
      <head><title>Ausgabe</title></head>
      <body>
        <xsl:apply-templates select="aktien/aktie"></xsl:apply-templates>
      </body>
    </html>
 
  </xsl:template>
 
  <xsl:template match="aktie">
     <xsl:if test="@isin">
       <xsl:value-of select="name" />
       <xsl:value-of select="fn:format-number(fn:sum(kurse/kurs/ausgabepreis) div fn:count(kurse/kurs), '##.00')" />    
     </xsl:if> 
  </xsl:template>

</xsl:stylesheet>
</code>
up
0
Jeroen
15 years ago
In addition to the contibution of "tom at kornack dot com" about converting an Apple plist (iPhoto or iTunes library or other) into a more general XML format, I have tried to simplify his xsl file a little further:

<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="no"/>                
<!-- XSL file based on example on php.net by tom@kornack.com -->

<xsl:template match="dict">                           
  <xsl:for-each select="key">
    <xsl:variable name="n1" select="translate(.,' ','_')"/>
    <xsl:variable name="pName"><xsl:choose>           
      <xsl:when test="string(number($n1))='NaN'">     
        <xsl:value-of select="$n1"/>                  
      </xsl:when>                                     
      <xsl:otherwise>                                 
        <xsl:value-of select="concat('_',$n1,'_')"/>  
      </xsl:otherwise>                                
    </xsl:choose></xsl:variable>                      
    <xsl:element name="{$pName}">                     
      <xsl:apply-templates select="following-sibling::*[1]"/>
    </xsl:element>
  </xsl:for-each>
</xsl:template>

<xsl:template match="array">                          
  <xsl:for-each select="*"><xsl:element name="item">  
    <xsl:attribute name="nr"><xsl:number/></xsl:attribute>
    <xsl:apply-templates select="."/>                 
  </xsl:element></xsl:for-each>                       
</xsl:template>

<xsl:template match="string|integer|real|date|data">  
  <xsl:value-of select="."/>                          
</xsl:template>

<xsl:template match="true|false">                     
  <xsl:value-of select="name()"/>                     
</xsl:template>

<xsl:template match="text()|@*">                      
</xsl:template>

</xsl:transform>
up
0
nicolas_rainardNOSPAM at yahoo dot fr
16 years ago
The XSLTProcessor, when transforming a document, always resolves entities.
To avoid this (if you want to keep HTML entitities by ex.), you have two solutions:

- if you have full control over the input document, you can encapsulate every text element which contains entities in a CDATA section.

- the previous solution is the smarter and the less computing intensive, but it is not always possible. In other cases, what you can do is to replace every occurence of '&' (entity mark) by something which will be considered as normal text by the parser (let's say '[AMP]' by ex) in the input document before the transformation. After the transformation, you can get these entitites back in the output document by reversing the previous operation.

<?php

$xml
= $input_dom->saveXML();
$xml = str_replace('&', '[AMP]', $xml);
$input_dom->loadXML($xml);

$xml = $xsl->transformToXML($input_dom);
$xml = str_replace('[AMP]', '&', $xml);
$output_dom->loadXML($xml);

?>

Warning : this second method "escapes" ALL entities, even those you wouldn't want to be escaped. This is a raw explanation, fine-tune it to your own situation.
up
0
Roman
17 years ago
bat at flurf, you said that Sablotron implements XSLT 1.1, but according to its makers, "Sablotron is ...implementing XSLT 1.0, DOM Level2 and XPath 1.0" [http://www.gingerall.org/sablotron.html]
up
0
will at NOSPAM dot wdp dot ndo dot co dot uk
20 years ago
As an update to the previous advice about the undefined references problem when installing PHP with Sablotron, PHP 4.3.4 has a new EXTRA_LDFLAGS_PROGRAM line added to the Makefile. Make sure to add -lstdc++ to this line as well as the EXTRA_LDFLAGS line.
up
0
crtn at users dot sourceforge dot net
20 years ago
Another way to get around the EXPAT-SABLOTRON problems (seg faults) is supposedly to recompile apache with:
--disable-rule=EXPAT
up
0
d dot brotherstone at pobox dot com
20 years ago
If you get problems with undefined references to gxx_s type stuff, UPDATE LIBTOOL!  I found 1.4.1 worked for some configurations, 1.4.3 worked for almost none, but 1.5 worked for every combination of Sablotron/gettext/sybase/zlib/postgres --with options I tried. 

Make sure you follow the advice of adding -lstdc++ to EXTRA_LD_FLAGS in Makefile after you've run ./configure, and BEFORE you've run make (if you issue make, you'll need to do a make clean before you make again, after changing the Makefile, or it still won't work reliably).

Cheers, Dave.
up
0
jw at shapers dot nl
21 years ago
In addition to "tk dot lists at fastmail dot fm"'s comment on Windows dependencies: You'll also need iconv.dll in your SYSTEM32 folder. At least, that's what I needed to get it working on my PHP4.2.3-Win install.
up
0
dennisNOSPAM at infoleak dot com
21 years ago
Building Sablotron on Solaris with.
gcc 3.0.3 and native linker
libtool (sunfreeware)
apache 1.3.24
php-4.2.1
sablotron-0.90
expat-1.95.2

When configuring Apache you might experience this error..

libsablot.so: undefined reference to `operator new[](unsigned)'
libsablot.so: undefined reference to `__cxa_call_unexpected'
libsablot.so: undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
libsablot.so: undefined reference to `operator delete(void*)'
libsablot.so: undefined reference to `__gxx_personality_v0'
libsablot.so: undefined reference to `vtable for __cxxabiv1::__class_type_info'
libsablot.so: undefined reference to `operator delete[](void*)'
libsablot.so: undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
libsablot.so: undefined reference to `operator new(unsigned)'

To cure it make sure that during the configure stage you feed configure LDFLAGS variable like so.

LDFLAGS=' -lstdc++' ./configure

Otherwise Apache's compiler sanity check will balk.
To Top