【发布时间】:2014-04-06 18:26:05
【问题描述】:
我想使用 java 传递一个属性值列表,并想检查它是否存在于特定节点的属性中。现在我需要写一个xslt来实现以下功能,请提供一些指导。
<!-- language: lang-xml -->
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<mtxml>
<Nav>
<DimVal Name="G" Id="10000" Flags="0" dim="10000" DdmName="Gender" >
<Property Key="A">10047</Property>
<Property Key="B">10048</Property>
<Property Key="C">10049</Property>
<Property Key="D">2082</Property>
<Property Key="G">22332</Property>
<Property Key="H">1121</Property>
<Property Key="I">2223</Property>
</DimVal>
<DimVal Name="A" Id="11000" Flags="0" dim="11000" DdmName="Address" >
<Property Key="A">10047</Property>
<Property Key="B">10048</Property>
<Property Key="D">2082</Property>
<Property Key="E">23343</Property>
<Property Key="F">3323</Property>
<Property Key="G">22332</Property>
<Property Key="H">1121</Property>
<Property Key="I">2223</Property>
</DimVal>
<DimVal Name="R" Id="11001" Flags="0" dim="11001" DdmName="Zip" >
<Property Key="A">10047</Property>
<Property Key="B">10048</Property>
<Property Key="C">44532</Property>
<Property Key="D">2082</Property>
<Property Key="E">23343</Property>
<Property Key="F">3323</Property>
<Property Key="G">22332</Property>
<Property Key="H">1121</Property>
<Property Key="I">2223</Property>
</DimVal>
</Nav>
<Nav>
<DimVal Name="GA" Id="90000" Flags="0" dim="90000" DdmName="Age" >
<Property Key="A">10047</Property>
<Property Key="D">2082</Property>
<Property Key="G">22332</Property>
<Property Key="H">1121</Property>
<Property Key="I">2223</Property>
</DimVal>
<DimVal Name="AL" Id="91000" Flags="0" dim="91000" DdmName="Route" >
<Property Key="A">10047</Property>
<Property Key="B">10048</Property>
<Property Key="D">2082</Property>
<Property Key="E">23343</Property>
<Property Key="F">3323</Property>
<Property Key="G">22332</Property>
<Property Key="H">1121</Property>
<Property Key="I">2223</Property>
</DimVal>
<DimVal Name="RW" Id="91001" Flags="0" dim="91001" DdmName="Postal Code" >
<Property Key="A">10047</Property>
<Property Key="B">10048</Property>
<Property Key="C">44532</Property>
<Property Key="D">2082</Property>
<Property Key="F">3323</Property>
<Property Key="G">22332</Property>
<Property Key="H">1121</Property>
</DimVal>
</Nav>
</mtxml>
我将使用以下设置参数,其中 parameterValue 是 Array/ArrayList
<!-- language: lang-java-->
xsltTransformer.setParameter(parameterName, parameterValue);
现在如果我通过 {'A','B','C','D','E','F','G','H','I'} 我会期待xslt 输出如下:
<!-- language: lang-xml -->
<DimVal Name="G" Id="10000" Flags="0" dim="10000" DdmName="Gender">
<Property Key="E" />
<Property Key="F" />
</DimVal>
<DimVal Name="A" Id="11000" Flags="0" dim="11000" DdmName="Address">
<Property Key="C" />
</DimVal>
<DimVal Name="GA" Id="90000" Flags="0" dim="90000" DdmName="Age" >
<Property Key="B" />
<Property Key="C" />
<Property Key="E" />
<Property Key="F" />
</DimVal>
<DimVal Name="AL" Id="91000" Flags="0" dim="91000" DdmName="Route" >
<Property Key="C" />
</DimVal>
<DimVal Name="RW" Id="91001" Flags="0" dim="91001" DdmName="Postal Code" >
<Property Key="E" />
<Property Key="I" />
</DimVal>
我没有合并任何 xslt(我无法解决),第一个 XML 是输入 xml,第二个是预期输出。传递的参数值是“Property”元素的“Key”属性的属性值列表。
【问题讨论】:
-
要读取 XLST 中的参数,您只需使用顶级
<xsl:param name="parameterName" />定义全局参数。你的parameterValue是字符串"{'A','B','C','D','E','F','G','H','I'}"吗?目前尚不清楚您是否包含源文档。这两份文件都是预期的结果吗? parameterValue 中发送的字母如何与结果 XML 相关? -
我没有合并任何 xslt,第一个 XML 是输入 xml,第二个是预期的输出。传递的参数值是“Property”元素的“Key”属性的属性值列表。
-
当您没有合并任何 XSLT 时,您希望如何从
xsltTransformer获得任何输出? -
输出是手动生成的,我想不出写XSLT来生成输出的方法。很高兴知道是否可以编写这样的 xslt,如果可以,有人可以为我提供一些指导
-
可以使用 XSLT 生成 XML,但必须了解转换背后的逻辑。例如:为什么结果中的 dimval
G具有E和F这两个属性?为什么dimvalA只包含propertyC?您的输入参数值{'A','B','C','D','E','F','G','H','I'}在该结果中起什么作用?例如,如果输入是{'A','F'},那么输出会发生什么变化。这就是这个问题所缺少的。