我尝试将一个XML文件转换为另一个使用Altova Map Force生成的XSLT的XML。
首先,当撒克逊处理器找不到此处描述的Altova特定功能时,我遇到了问题:http://manual.altova.com/stylevision/stylevisionenterprise/index.html?fxaltova_xpxqnumeric.htm
我的XSLT中使用的函数是“generate-auto-number”和“reset-auto-number”。
问题是“AltovaXSLT.xslt第41行第85行的xsl:variable错误: XPST0017在第41行的char 0附近的XPath语法错误... r('mapforce_autonumber_153336056'): 找不到匹配的4参数函数,名为://www.altova.com/xslt-extensions} reset-auto-number()“
我通过在saxon处理器中使用registerExtensionFunction来解决这个问题。
但是,我的函数只调用一次。在输出XML中,a可以看到我生成的数字但总是相同的数字。 我做错了什么,请帮帮忙?
输入XML:
<?xml version="1.0" encoding="UTF-8"?>
<Results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="PassThrough.xsd"
FileType="Snapshot"
ODMVersion="1.3.2"
dataSet="1.0.0"
FileOID="482ea709-3e9c-46f5-86ed-1344963b81a4"
CreationDtateTime="2015-09-28T11:51:59.548-04:00">
<Study StudyOID="Some Study OID">
<MetadataInfo MetadataVersionOID="v1.3.2" MetadataVersionName="Version 1.3.2"/>
<StudyName>Some name</StudyName>
<StudyDescription/>
<ProtocolName>Some name</ProtocolName>
</Study>
<Patient StudyOID="Some study OID"
SubjectKey="11"
MetaDataVersionOID="v1.3.2"
Visit="SE.week_24_arm_1">
<Item StudyEventOID="SE.day_1_arm_1"
FormOID="FM.subject_enrollment_form"
ItemGroupOID="IG.subject_enrollment_form"
ItemOID="IT.record_id"
ItemValue="11"/>
<Item StudyEventOID="SE.day_1_arm_1"
FormOID="FM.demographics"
ItemGroupOID="IG.demographics"
ItemOID="IT.dm_sex"
ItemValue="F"/>
<Item StudyEventOID="SE.day_1_arm_1"
FormOID="FM.demographics"
ItemGroupOID="IG.demographics"
ItemOID="IT.dm_ethnic"
ItemValue="HISPANIC_OR_LATINO"/>
........
....
........
</Patient>
</Results>
XSLT转换:
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file was generated by Altova MapForce 2015r4sp1
YOU SHOULD NOT MODIFY THIS FILE, BECAUSE IT WILL BE
OVERWRITTEN WHEN YOU RE-RUN CODE GENERATION.
Refer to the Altova MapForce Documentation for further details.
http://www.altova.com/mapforce
-->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:vmf="http://www.altova.com/MapForce/UDF/vmf" xmlns:ns0="http://www.altova.com/xslt-extensions" xmlns:ns1="http://www.cdisc.org/ns/odm/v1.3" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="vmf ns0 ns1 xs fn">
<xsl:template name="vmf:vmf1_inputtoresult">
<xsl:param name="input" select="()"/>
<xsl:choose>
<xsl:when test="$input='SE.week_24_arm_2'">
<xsl:copy-of select="'WEEK 24'"/>
</xsl:when>
<xsl:when test="$input='SE.day_28_arm_2'">
<xsl:copy-of select="'DAY 28'"/>
</xsl:when>
<xsl:when test="$input='SE.day_0_arm_2'">
<xsl:copy-of select="'BASELINE'"/>
</xsl:when>
<xsl:when test="$input='SE.day_3_arm_3'">
<xsl:copy-of select="'DAY 3'"/>
</xsl:when>
<xsl:when test="$input='SE.day_7_arm_3'">
<xsl:copy-of select="'DAY 7'"/>
</xsl:when>
<xsl:when test="$input='SE.day_14_arm_3'">
<xsl:copy-of select="'DAY 14'"/>
</xsl:when>
<xsl:when test="$input='SE.day_0_arm_3'">
<xsl:copy-of select="'BASELINE'"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:output method="xml" encoding="UTF-8" byte-order-mark="no" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="var13_Results" as="node()?" select="Results"/>
<xsl:sequence select="ns0:reset-auto-number('mapforce_autonumber_153336056')"/>
<ODM xmlns="http://www.cdisc.org/ns/odm/v1.3" xmlns:data="http://www.cdisc.org/ns/Dataset-XML/v1.0">
<xsl:for-each select="$var13_Results[fn:exists(@FileType)]">
<xsl:attribute name="FileType" namespace="" select="fn:string(@FileType)"/>
</xsl:for-each>
<xsl:for-each select="$var13_Results[fn:exists(@ODMVersion)]">
<xsl:attribute name="ODMVersion" namespace="" select="fn:string(@ODMVersion)"/>
</xsl:for-each>
<xsl:for-each select="$var13_Results[fn:exists(@dataSet)]">
<xsl:attribute name="data:DatasetXMLVersion" select="fn:string(@dataSet)"/>
</xsl:for-each>
<xsl:for-each select="$var13_Results[fn:exists(@FileOID)]">
<xsl:attribute name="FileOID" namespace="" select="fn:string(@FileOID)"/>
</xsl:for-each>
<xsl:for-each select="$var13_Results[fn:exists(@PriorFileOID)]">
<xsl:attribute name="PriorFileOID" namespace="" select="fn:string(@PriorFileOID)"/>
</xsl:for-each>
<xsl:for-each select="$var13_Results[fn:exists(@Originator)]">
<xsl:attribute name="Originator" namespace="" select="fn:string(@Originator)"/>
</xsl:for-each>
<xsl:for-each select="$var13_Results[fn:exists(@CreationDtateTime)]">
<xsl:attribute name="CreationDateTime" namespace="" select="fn:string(@CreationDtateTime)"/>
</xsl:for-each>
<xsl:for-each select="$var13_Results">
<xsl:variable name="var12_current" as="node()" select="."/>
<xsl:for-each select="*:Study[fn:namespace-uri() eq '']">
<xsl:variable name="var11_StudyOID" as="node()?" select="@StudyOID"/>
<xsl:variable name="var10_resultof_exists" as="xs:boolean" select="fn:exists($var11_StudyOID)"/>
<ClinicalData>
<xsl:if test="$var10_resultof_exists">
<xsl:attribute name="StudyOID" namespace="" select="fn:string($var11_StudyOID)"/>
</xsl:if>
<xsl:for-each select="*:MetadataInfo[fn:namespace-uri() eq ''][fn:exists(@MetadataVersionOID)]">
<xsl:attribute name="MetaDataVersionOID" namespace="" select="fn:string(@MetadataVersionOID)"/>
</xsl:for-each>
<xsl:for-each select="$var12_current/*:Patient[fn:namespace-uri() eq '']">
<xsl:variable name="var9_resultof_cast" as="xs:string" select="fn:string(@SubjectKey)"/>
<xsl:variable name="var7_resultof_vmf__inputtoresult" as="xs:string?">
<xsl:call-template name="vmf:vmf1_inputtoresult">
<xsl:with-param name="input" select="fn:string(@Visit)" as="xs:string"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="var8_resultof_filter" as="node()*" select="*:Item[fn:namespace-uri() eq ''][fn:exists(@ItemOID)]"/>
<xsl:variable name="var6_resultof_filter" as="node()*" select="$var8_resultof_filter[(fn:string(@ItemOID) = 'IT.dm_race')]"/>
<xsl:variable name="var5_resultof_filter" as="node()*" select="$var6_resultof_filter[fn:exists(@ItemValue)]"/>
<xsl:variable name="var3_resultof_map" as="item()*">
<xsl:for-each select="$var5_resultof_filter">
<xsl:sequence select="fn:string(@ItemValue)"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="var4_resultof_equal" as="xs:boolean" select="(fn:count($var3_resultof_map) = xs:decimal('1'))"/>
<ItemGroupData>
<xsl:attribute name="ItemGroupOID" namespace="" select="'IG.DM'"/>
<xsl:variable name="var1_resultof_auto_number" as="xs:integer" select="ns0:generate-auto-number('mapforce_autonumber_153336056', xs:integer('1'), xs:integer('1'), '')"/>
<xsl:attribute name="data:ItemGroupDataSeq" select="xs:string($var1_resultof_auto_number)"/>
<ItemData>
<xsl:attribute name="ItemOID" namespace="" select="'IT.STUDYID'"/>
<xsl:if test="$var10_resultof_exists">
<xsl:attribute name="Value" namespace="" select="fn:string($var11_StudyOID)"/>
</xsl:if>
</ItemData>
<ItemData>
<xsl:attribute name="ItemOID" namespace="" select="'IT.DM.DOMAIN'"/>
<xsl:attribute name="Value" namespace="" select="'DM'"/>
</ItemData>
<ItemData>
<xsl:attribute name="ItemOID" namespace="" select="'IT.USUBJID'"/>
<xsl:attribute name="Value" namespace="" select="$var9_resultof_cast"/>
</ItemData>
<ItemData>
<xsl:attribute name="ItemOID" namespace="" select="'IT.DM.SUBJID'"/>
<xsl:attribute name="Value" namespace="" select="$var9_resultof_cast"/>
</ItemData>
<xsl:for-each select="$var8_resultof_filter[fn:starts-with(fn:string(@ItemOID), 'IT.site_name')][fn:exists(@ItemValue)]">
<ItemData>
<xsl:attribute name="ItemOID" namespace="" select="'IT.DM.SITEID'"/>
<xsl:attribute name="Value" namespace="" select="fn:string(@ItemValue)"/>
</ItemData>
</xsl:for-each>
<xsl:for-each select="$var8_resultof_filter[fn:starts-with(fn:string(@ItemOID), 'IT.dm_birthyr')][fn:exists(@ItemValue)]">
<ItemData>
<xsl:attribute name="ItemOID" namespace="" select="'IT.DM.BRTHDTC'"/>
<xsl:attribute name="Value" namespace="" select="fn:string(@ItemValue)"/>
</ItemData>
</xsl:for-each>
<xsl:for-each select="$var8_resultof_filter[fn:starts-with(fn:string(@ItemOID), 'IT.dm_sex')][fn:exists(@ItemValue)]">
<ItemData>
<xsl:attribute name="ItemOID" namespace="" select="'IT.DM.SEX'"/>
<xsl:attribute name="Value" namespace="" select="fn:string(@ItemValue)"/>
</ItemData>
</xsl:for-each>
<xsl:if test="(fn:not($var4_resultof_equal) or fn:exists($var6_resultof_filter[fn:exists(@ItemValue)]))">
<ItemData>
<xsl:attribute name="ItemOID" namespace="" select="'IT.DM.RACE'"/>
<xsl:attribute name="Value" namespace="">
<xsl:choose>
<xsl:when test="$var4_resultof_equal">
<xsl:variable name="var2_resultof_map" as="xs:string*">
<xsl:for-each select="$var5_resultof_filter">
<xsl:sequence select="fn:string(@ItemValue)"/>
</xsl:for-each>
</xsl:variable>
<xsl:sequence select="xs:string(fn:string-join(for $x in $var2_resultof_map return xs:string($x), ' '))"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="'MULTIPLE'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</ItemData>
</xsl:if>
<xsl:for-each select="$var8_resultof_filter[fn:starts-with(fn:string(@ItemOID), 'IT.dm_ethnic')][fn:exists(@ItemValue)]">
<ItemData>
<xsl:attribute name="ItemOID" namespace="" select="'IT.DM.ETHNIC'"/>
<xsl:attribute name="Value" namespace="" select="fn:string(@ItemValue)"/>
</ItemData>
</xsl:for-each>
<ItemData>
<xsl:if test="fn:exists($var7_resultof_vmf__inputtoresult)">
<xsl:attribute name="Value" namespace="" select="$var7_resultof_vmf__inputtoresult"/>
</xsl:if>
</ItemData>
</ItemGroupData>
</xsl:for-each>
</ClinicalData>
</xsl:for-each>
</xsl:for-each>
</ODM>
</xsl:template>
</xsl:stylesheet>
和Java代码:
Processor processor = new Processor(true);
processor.registerExtensionFunction(new GenerateAutoNumberExtDefinition());
processor.registerExtensionFunction(new ResetAutoNumberExtDefinition());
XdmNode input = processor.newDocumentBuilder().build(inputXML);
Xslt30Transformer transformer = processor.newXsltCompiler().compile(xsltSource).load30();
StringWriter outputStream = new StringWriter();
transformer.applyTemplates(input, processor.newSerializer(outputStream));
GenerateAutoNumberExtDefinition实现变量的增量。我甚至尝试调试这个,我确信它只被调用一次。
结果XML是:
<?xml version="1.0" encoding="UTF-8"?>
<ODM xmlns="http://www.cdisc.org/ns/odm/v1.3"
xmlns:data="http://www.cdisc.org/ns/Dataset-XML/v1.0"
FileType="Snapshot"
ODMVersion="1.3.2"
data:DatasetXMLVersion="1.0.0"
FileOID="c293a323-31a0-4df3-94b4-2876f62b8193"
CreationDateTime="2015-10-01T15:41:57.216-04:00">
<ClinicalData StudyOID="Some OID"
MetaDataVersionOID="2015-06-30T09:45:09.000-04:00">
<ItemGroupData ItemGroupOID="IG.DM" data:ItemGroupDataSeq="1">
<ItemData ItemOID="IT.STUDYID" Value="Some OID"/>
<ItemData ItemOID="IT.DM.DOMAIN" Value="DM"/>
<ItemData ItemOID="IT.USUBJID" Value="11"/>
<ItemData ItemOID="IT.DM.SUBJID" Value="11"/>
<ItemData ItemOID="IT.DM.SEX" Value="F"/>
<ItemData ItemOID="IT.DM.RACE" Value="ASIAN"/>
<ItemData ItemOID="IT.DM.ETHNIC" Value="HISPANIC_OR_LATINO"/>
<ItemData/>
</ItemGroupData>
<ItemGroupData ItemGroupOID="IG.DM" data:ItemGroupDataSeq="1">
<ItemData ItemOID="IT.STUDYID" Value="Some OID"/>
<ItemData ItemOID="IT.DM.DOMAIN" Value="DM"/>
<ItemData ItemOID="IT.USUBJID" Value="12"/>
<ItemData ItemOID="IT.DM.SUBJID" Value="12"/>
<ItemData ItemOID="IT.DM.SEX" Value="M"/>
<ItemData ItemOID="IT.DM.RACE" Value="MULTIPLE"/>
<ItemData ItemOID="IT.DM.ETHNIC" Value="HISPANIC_OR_LATINO"/>
<ItemData/>
</ItemGroupData>
<ItemGroupData ItemGroupOID="IG.DM" data:ItemGroupDataSeq="1">
<ItemData ItemOID="IT.STUDYID" Value="Some OID"/>
<ItemData ItemOID="IT.DM.DOMAIN" Value="DM"/>
<ItemData ItemOID="IT.USUBJID" Value="14"/>
<ItemData ItemOID="IT.DM.SUBJID" Value="14"/>
<ItemData ItemOID="IT.DM.SEX" Value="M"/>
<ItemData ItemOID="IT.DM.RACE" Value="NATIVE_HAWAIIAN_OR_OTHER_PACIFIC_ISLANDER"/>
<ItemData ItemOID="IT.DM.ETHNIC" Value="NOT_HISPANIC_OR_LATINO"/>
<ItemData/>
</ItemGroupData>
<ItemGroupData ItemGroupOID="IG.DM" data:ItemGroupDataSeq="1">
<ItemData ItemOID="IT.STUDYID" Value="Some OID"/>
<ItemData ItemOID="IT.DM.DOMAIN" Value="DM"/>
<ItemData ItemOID="IT.USUBJID" Value="12344"/>
<ItemData ItemOID="IT.DM.SUBJID" Value="12344"/>
<ItemData ItemOID="IT.DM.SEX" Value="UNDIFFERENTIATED"/>
<ItemData ItemOID="IT.DM.RACE" Value="MULTIPLE"/>
<ItemData ItemOID="IT.DM.ETHNIC" Value="UNKNOWN"/>
<ItemData/>
</ItemGroupData>
<ItemGroupData ItemGroupOID="IG.DM" data:ItemGroupDataSeq="1">
<ItemData ItemOID="IT.STUDYID" Value="Some OID"/>
<ItemData ItemOID="IT.DM.DOMAIN" Value="DM"/>
<ItemData ItemOID="IT.USUBJID" Value="22333"/>
<ItemData ItemOID="IT.DM.SUBJID" Value="22333"/>
<ItemData ItemOID="IT.DM.RACE" Value="MULTIPLE"/>
<ItemData/>
</ItemGroupData>
<ItemGroupData ItemGroupOID="IG.DM" data:ItemGroupDataSeq="1">
<ItemData ItemOID="IT.STUDYID" Value="Some OID"/>
<ItemData ItemOID="IT.DM.DOMAIN" Value="DM"/>
<ItemData ItemOID="IT.USUBJID" Value="22334"/>
<ItemData ItemOID="IT.DM.SUBJID" Value="22334"/>
<ItemData ItemOID="IT.DM.RACE" Value="MULTIPLE"/>
<ItemData/>
</ItemGroupData>
<ItemGroupData ItemGroupOID="IG.DM" data:ItemGroupDataSeq="1">
<ItemData ItemOID="IT.STUDYID" Value="Some OID"/>
<ItemData ItemOID="IT.DM.DOMAIN" Value="DM"/>
<ItemData ItemOID="IT.USUBJID" Value="22335"/>
<ItemData ItemOID="IT.DM.SUBJID" Value="22335"/>
<ItemData ItemOID="IT.DM.RACE" Value="MULTIPLE"/>
<ItemData/>
</ItemGroupData>
<ItemGroupData ItemGroupOID="IG.DM" data:ItemGroupDataSeq="1">
<ItemData ItemOID="IT.STUDYID" Value="Some OID"/>
<ItemData ItemOID="IT.DM.DOMAIN" Value="DM"/>
<ItemData ItemOID="IT.USUBJID" Value="22336"/>
<ItemData ItemOID="IT.DM.SUBJID" Value="22336"/>
<ItemData ItemOID="IT.DM.SEX" Value="F"/>
<ItemData ItemOID="IT.DM.RACE" Value="MULTIPLE"/>
<ItemData ItemOID="IT.DM.ETHNIC" Value="NOT_REPORTED"/>
<ItemData/>
</ItemGroupData>
</ClinicalData>
</ODM>
正如您在每个数据中看到的那样:ItemGroupDataSeq值为“1”但它应该递增。
答案 0 :(得分:0)
难道你不能简单地使用纯XSLT来解决这个问题吗? <xsl:attribute name="data:ItemGroupDataSeq"><xsl:number/></xsl:attribute>
以及<xsl:attribute name="data:ItemGroupDataSeq" select="position()"/>
个for-each
元素内的Patient
甚至{{1}}都应该这样做。
如果您需要有关扩展功能的帮助,我们需要查看它们的实现。
答案 1 :(得分:0)
实际上,上述方法是有效的。但不是因为我的具体情况,当我需要一些时间重置计数器并再次开始计数(功能正在做什么)。
但是我可以通过覆盖ExtensionFunctionDefinition类中的函数dependsOnFocus来解决这个问题。
@Override
public boolean dependsOnFocus() {
return true;
}
如果值为false,则它看起来像缓存。如果参数没有改变,那么该函数只调用一次。通过dependsOnFocus方法返回true允许我们依赖于xslt中的函数位置而不依赖于参数。