Friday, 15 April 2011

xslt - XSL conversion from 2.0 -



xslt - XSL conversion from 2.0 -

i have problem converting xslt 2.0 xslt 3.0. want utilize streaming capability of xslt 3.0. struggling using <xsl:stream> , <xsl:mode> tags xslt 3.0 has several restrictions. using xslt 3.0 streaming capabilities, next restrictions faced:

“sibling nodes , ancestor sibling not reachable”. "you can visit kid nodes once" "you have access current element attributes , namespace declaration"

how can overcome these restrictions? can please help me?

<?xml version="1.0" encoding="utf-8"> <xsl:stream href="sampleinput3_0.xml"> <xsl:for-each select="copy-of(ns0:orm_o01/ns0:orm_o01.patient/ns0:pid)"> <patient> <ucfd:name> <xsl:variable name="varfirst_name" as="node()" select="ns0:pid.5/ns0:xpn.2[not((translate(string(@xsi:nil), 'true ', '1') = '1'))]" /> <xsl:variable name="varlast_name" as="node()" select="ns0:xpn.1/ns0:fn.1[not((translate(string(@xsi:nil), 'true ', '1') = '1'))]" /> <xsl:attribute name="value" namespace="" select="concat(string($varfirst_name), string(varlast_name))" /> </ucfd:name> <ucfd:firstname value="{ns0:pid.5/ns0:xpn.2[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <ucfd:lastname value="{ns0:pid.5/ns0:xpn.1/ns0:fn.1}" /> <ucfd:middlename value="{ns0:pid.5/ns0:xpn.3[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <ucfd:prefix value="{ns0:pid.5/ns0:xpn.5[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <ucfd:suffix value="{ns0:pid.5/ns0:xpn.4[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <ucfd:identification> <ucfd:taxidentifier> <ucfd:type value="{ns0:pid.18/ns0:cx.5[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <ucfd:identifier value="{ns0:pid.18/ns0:cx.1}" /> </ucfd:taxidentifier> </ucfd:identification> <xsl:for-each select="ns0:pid.11"> <ucfd:address> <xsl:if test="exists(@type)"> <ucfd:type value="{ns0:xad.7[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> </xsl:if> <ucfd:city value="{ns0:xad.3[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <ucfd:state value="{ns0:xad.4[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <ucfd:postalcode value="{ns0:xad.5[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <ucfd:country value="{ns0:xad.6[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <ucfd:county value="{ns0:xad.9[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> </ucfd:address> </xsl:for-each> <ucfd:contact> <ucfd:role value="{ns0:pid.13/ns0:xtn.2[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <ucfd:type value="{ns0:pid.13/ns0:xtn.3[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <xsl:for-each select="ns0:pid.13"> <!--<xsl:variable name="var9_current" as="node()" select="."/>--> <ucfd:communicationnumber> <xsl:if test="exists(@type)"> <ucfd:type> <xsl:sequence select="()" /> </ucfd:type> </xsl:if> <ucfd:identifier> <!--<xsl:variable name="var8_current" as="node()" select="ns0:xtn.5[not((translate(string(@xsi:nil), 'true ', '1') = '1'))]"/> <xsl:variable name="var7_current" as="node()" select="ns0:xtn.6[not((translate(string(@xsi:nil), 'true ', '1') = '1'))]"/> <xsl:variable name="var6_current" as="node()" select="ns0:xtn.7[not((translate(string(@xsi:nil), 'true ', '1') = '1'))]"/> <xsl:variable name="var5_current" as="node()" select="ns0:xtn.8[not((translate(string(@xsi:nil), 'true ', '1') = '1'))]"/> <xsl:variable name="var4_current" as="node()" select="ns0:xtn.10[not((translate(string(@xsi:nil), 'true ', '1') = '1'))]"/> <xsl:variable name="var3_current" as="node()" select="ns0:xtn.11[not((translate(string(@xsi:nil), 'true ', '1') = '1'))]"/> <xsl:attribute name="value" namespace="" select="concat(concat(concat(concat(concat(string($var8_current), string($var7_current)), string($var6_current)), string($var5_current)), string($var4_current)), string($var3_current))"/> --> </ucfd:identifier> </ucfd:communicationnumber> </xsl:for-each> </ucfd:contact> <ucfd:demographics> <ucfd:birthdate> <xsl:sequence select="()" /> </ucfd:birthdate> <ucfd:birthsequencenumber> <xsl:for-each select="ns0:orm_o01/ns0:orm_o01.patient/ns0:pid/ns0:pid.25"> <xsl:attribute name="value" namespace=""> <xsl:if test="not((translate(string(@xsi:nil), 'true ', '1') = '1'))"> <xsl:sequence select="xs:string(xs:integer(string(.)))" /> </xsl:if> </xsl:attribute> </xsl:for-each> </ucfd:birthsequencenumber> <ucfd:deathdate> <xsl:sequence select="()" /> </ucfd:deathdate> <ucfd:gender value="ns0:pid.8[not((translate(string(@xsi:nil), 'true ', '1') = '1'))]" /> <ucfd:maritalstatus value="{ns0:pid.16/ns0:ce_0002.1[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <ucfd:citizenshipstatus value="{ns0:pid.26[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <ucfd:raceorethnicity> <ucfd:race value="{ns0:pid.10/ns0:ce_0005.1[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> </ucfd:raceorethnicity> <ucfd:religion value="{ns0:pid.17/ns0:ce_0006.2[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> </ucfd:demographics> <ucfd:language> <ucfd:languagecode value="{ns0:pid.15/ns0:ce_0296.1[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <ucfd:description value="{ns0:pid.15/ns0:ce_0296.2[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> <ucfd:useindicator value="{ns0:pid.15/ns0:ce_0296.3[not(translate(@xsi:nil, 'true ', '1') = '1')]}" /> </ucfd:language> </patient> </xsl:for-each> </xsl:stream> </memberrecord> </xsl:template> </xsl:stylesheet>

i think should follow approach in http://saxonica.com/documentation/index.html#!sourcedocs/streaming/burst-mode-streaming along lines of

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:ns0="..." xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="..." xmlns:ccfd="..." xmlns:hcfd="..." xmlns:ucf="..." xmlns:ucfd="..." exclude-result-prefixes="ns0 xs"> <xsl:output method="xml" encoding="utf-8" byte-order-mark="no" indent="yes"/> <!-- start named template --> <xsl:template name="main"> <memberrecord xsi:schemalocation="..."> <patient> <xsl:stream href='employees.xml'> <xsl:apply-templates select="copy-of(ns0:orm_o01/ns0:orm_o01.patient/ns0:pid)"/> </xsl:stream> </patient> </memberrecord> </xsl:template> <xsl:template match="ns0:pid"> <ucfd:name value="{...}"/> <ucfd:firstname value="{ns0:pid.5/ns0:xpn.2[not(translate(@xsi:nil, 'true ', '1') = '1'))]}"/> <ucfd:lastname value="{ns0:pid.5/ns0:xpn.1/ns0:fn.1}"/> <!-- compute other elements , attributes here above --> </xsl:template> </xsl:stylesheet>

that should show approach, have add together code remaining elements middle name , prefix , on. have tried simplify compuation of attribute value in cases, think same can done other cases think should inquire in different question provide details of xml construction , values want compute, nested for-eachs generate single value attribute seem bit convoluted.

also note have followed posted code in creating single patient element, expected ns0:orm_o01.patient element mapped patient more along lines of

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:ns0="..." xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="..." xmlns:ccfd="..." xmlns:hcfd="..." xmlns:ucf="..." xmlns:ucfd="..." exclude-result-prefixes="ns0 xs"> <xsl:output method="xml" encoding="utf-8" byte-order-mark="no" indent="yes"/> <!-- start named template --> <xsl:template name="main"> <memberrecord xsi:schemalocation="..."> <xsl:stream href='employees.xml'> <xsl:apply-templates select="copy-of(ns0:orm_o01/ns0:orm_o01.patient)"/> </xsl:stream> </patient> </memberrecord> </xsl:template> <xsl:template match="ns0:orm_o01.patient"> <patient> <xsl:apply-templates/> </patient> </xsl:template> <xsl:template match="ns0:pid"> <ucfd:name value="{...}"/> <ucfd:firstname value="{ns0:pid.5/ns0:xpn.2[not(translate(@xsi:nil, 'true ', '1') = '1'))]}"/> <ucfd:lastname value="{ns0:pid.5/ns0:xpn.1/ns0:fn.1}"/> <!-- compute other elements , attributes here above --> </xsl:template> </xsl:stylesheet>

xslt xslt-3.0

No comments:

Post a Comment