简体   繁体   中英

how to convert xslt version 2.0 to version 1.0

i am using xslt document which uses xpath version 2 functions. I only have xalan 2.6 jar which has xslt 1.0 processor, its a constraint i cannot change it..please help me if there are any tools that convert xpath 2.0 functions to 1.0

<xsl:variable name="var1_ClinicalDocument" as="node()?" select="ns0:ClinicalDocument"/>
        <DSMessage>
            <DSPatient>
                <xsl:for-each 

    select="$var1_ClinicalDocument[fn:exists(ns0:id/@root)]">
                        <Source>
                            <xsl:sequence select="fn:string(ns0:id/@root)"/>
                        </Source>
                    </xsl:for-each>
                    <Demographics>
                        <xsl:for-each select="($var1_ClinicalDocument/ns0:recordTarget/ns0:patientRole/ns0:id)[fn:exists(@extension)]">
                            <externalID>
                                <xsl:sequence select="fn:string(@extension)"/>
                            </externalID>
                        </xsl:for-each>
                        <xsl:for-each select="($var1_ClinicalDocument/ns0:recordTarget/ns0:patientRole/ns0:patient/ns0:name/ns0:given/node())[fn:boolean(self::text())]">
                            <firstName>
                                <xsl:sequence select="fn:string(.)"/>
                            </firstName>

Here is a mapping of the XPath 2.0 functions in question:

XPath 2.0     XPath 1.0                     Xalan-Java     XSLT-C
fn:exists()   string-length(concat(., ) )   XPath 1.0      XPath 1.0
fn:string()   string()                      XPath 1.0      XPath 1.0
fn:boolean()  boolean()                     XPath 1.0      XPath 1.0

EXSLT, XSLTSL, FXSL, and XPath algorithms can fill in most of the remaining functionality.

XPath 2.0               FXSL     XSLTSL                       EXSLT               XPath 1.0
fn:max                  maximum                               math:max
fn:max                                                        dyn:max
fn:min                  minimum                               math:min
fn:min                                                        dyn:min
fn:sum                  sum                                   math:sum            sum
fn:sum                                                        dyn:sum
fn:avg                                                                            sum div count
fn:floor                                                                          floor
fn:ceiling                                                                        ceiling
fn:round                                                                          round
fn:abs                                                        math:abs
fn:collection           foldl
op:concatenate          append
fn:doc                                                                            document
fn:count                                                                          count
fn:not                                                                            not
fn:true                                                                           true
fn:false                                                                          false
fn:boolean                                                                        boolean
fn:upper-case                    str:to-upper
fn:lower-case                    str:to-lower
fn:substring                                                                      substring
fn:string-length                                                                  string-length
fn:normalize-space                                                                normalize-space
fn:translate                                                                      translate
fn:concat                        str:concat                                       concat
fn:substring-before                                                               substring-before
fn:substring-after                                                                substring-after
fn:reverse                       str:backward
fn:insert-before                 str:insert-at        
fn:matches                       str:string-match
fn:tokenize                                                   str:tokenize
fn:resolve-uri                   uri:resolve-uri
fn:distinct-values                                            set:distinct 
op:union                                                                          |
op:intersect                                                  set:intersection
op:except                        cmp:diff                     set:difference
op:is-same-node                  cmp:cmp
fn:position                      node:xpath                                       position
fn:last                                                                           last
fn:data                          node:type
fn:lang                                                                           lang
fn:current-dateTime                                           date:date-time
fn:dateTime                      dt:format-date-time          date:format-date
fn:year-from-date                dt:get-xsd-datetime-year     date:day-in-year
fn:month-from-dateTime           dt:get-xsd-datetime-month    date:month-name
fn:day-from-dateTime             dt:get-xsd-datetime-day      date:day-name 
fn:hours-from-dateTime           dt:get-xsd-datetime-hour     date:hour-in-day
fn:minutes-from-dateTime         dt:get-xsd-datetime-minute   date:minute-in-hour
fn:seconds-from-dateTime         dt:get-xsd-datetime-second   date:second-in-minute
fn:timezone-from-dateTime        dt:get-xsd-datetime-timezone
if (...) then (...) else(...)                                                     $dynamic[$var] | $default[not($var)]

References

I will try, but this is untested:

<xsl:variable name="var1_ClinicalDocument" select="ns0:ClinicalDocument"/>
        <DSMessage>
            <DSPatient>
                <xsl:for-each 

    select="$var1_ClinicalDocument[ns0:id/@root]">
                        <Source>
                            <xsl:value-of select="ns0:id/@root"/>
                        </Source>
                    </xsl:for-each>
                    <Demographics>
                        <xsl:for-each select="($var1_ClinicalDocument/ns0:recordTarget/ns0:patientRole/ns0:id)[@extension]">
                            <externalID>
                                <xsl:value-of select="@extension"/>
                            </externalID>
                        </xsl:for-each>
                        <xsl:for-each select="($var1_ClinicalDocument/ns0:recordTarget/ns0:patientRole/ns0:patient/ns0:name/ns0:given/node())[self::text()]">
                            <firstName>
                                <xsl:value-of select="."/>
                            </firstName>

Basically the use of fn:exists , fn:string and fn:boolean can be replaced, of course if there is use of XPath/XSLT 2.0 stuff like tokenize or for-each-group you need more work and maybe Xalan specific extension functions.

This should be a not-bad translation :

    <xsl:variable name="var1_ClinicalDocument" select="ns0:ClinicalDocument"/>
    <DSMessage>
      <DSPatient>
        <xsl:for-each select="$var1_ClinicalDocument[ns0:id/@root]">
          <Source>
            <xsl:value-of select="ns0:id/@root"/>
          </Source>
        </xsl:for-each>
        <Demographics>
          <xsl:for-each select=
            "($var1_ClinicalDocument/ns0:recordTarget
                     /ns0:patientRole/ns0:id)[@extension]">
            <externalID>
             <xsl:value-of select="concat(@extension, ' ')"/>
            </externalID>
          </xsl:for-each>
          <xsl:for-each select=
           "$var1_ClinicalDocument/ns0:recordTarget/ns0:patientRole
                                  /ns0:patient/ns0:name/ns0:given/text()">
            <firstName>
              <xsl:value-of select="."/>
            </firstName>
          </xsl:for-each>
        </Demographics>
       </DSPatient>
    </DSMessage>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM