xml - Alternatives for XSLT transformations with Delphi XE8 -
i trying perform xslt transformation delphi xe8 , running problems. xsl file refers external xsl file using import statement href attribute has relative path. transform fails error "named template 'skrivutdate' not appear in stylesheet." definition 'skrivutdate' located in external xsl file. definition looks following:
<xsl:template name="skrivutdate"> <xsl:param name="oppgitttid"/> <xsl:if test="string-length($oppgitttid)!=0"> <xsl:value-of select="substring($oppgitttid,9,2)"/>.<xsl:value-of select="substring($oppgitttid,6,2)"/>.<xsl:value-of select="substring($oppgitttid,3,2)"/> </xsl:if> </xsl:template>
i have placed external xsl file in appropriate directory (relative original xsl file) same error (i have tried other conceivable directories external file, none have worked). however, can perform transformation using editx xml editor, not think xsl invalid (note xsl file provided third party, , apparently being used folks using development platforms other delphi).
here opening segment of xsl file:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:ref="http://www.kith.no/xmlstds/henvisning/2012-02-15" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:po="http://www.kith.no/xmlstds/po/pokomponent/2009-06-30" xmlns:fk1="http://www.kith.no/xmlstds/felleskomponent1" exclude-result-prefixes="ref xhtml po fk1"> <xsl:import href="../../felleskomponenter/funksjoner.xsl"/>
and, yes, funksjoner.xsl file in directory named felleskomponenter.
my simple test uses similar following pseudo code:
var xml : ixmldocument; xsl : ixmldocument; s: widestring; begin xml := txmldocument.create(self); xml.filename := 'c:\somepath\some.xml'; xml.active := true; xsl := txmldocument.create(self); xsl.filename := 'c:\someotherpath\somefile.xsl'; xsl.active := true; xml.documentelement.transformnode(xsl.documentelement, s);
i know delphi xe7 started shipping omni xml dom adom, apparently absent delphi xe8. hoping using different document object model might address problem.
the xml pretty complicated, xsl.
does body have suggestions alternative ways perform xslt transformations delphi xe8?
for xslt work in delphi, need use msxml load xml , xsl files. post gives an example on how use msxml delphi. transformnode
uses msxml under hood.
something along following should work (taken from here, incomplete snippet):
var xmlemployees, xslstyle : ixmldomdocument; begin xmlemployees := codomdocument.create; xslstyle := codomdocument.create; xmlemployees.load('employees.xml'); xslstyle.load('empuksna.xsl'); result := xmlemployees.transformnode(xslstyle); end;
likewise, if load xml , xsl through string, original location gets lost. processors support setting base uri, looks ixslprocessor not have such option.
you ask alternative. dixml support libxslt in quite respects superior msxml (though not .net's xslt, alternative, if interop'ing .net). the package of dixml comes bunch of demo's , examples in demo folder.
if can switch .net, this (rather old) drdobb's article shows how xslt .net , delphi , shows yet alternative transformation (though assumed delphi 7, not sure still applies).
Comments
Post a Comment