【发布时间】:2020-02-14 07:41:48
【问题描述】:
我想创建一个 xslt 转换,它将基于结构的属性转换为单值字符串,最好是通用的,这样就不会从输入中引用命名项。
示例输入:
<attr attr-name="items">
<value type="structured">
<component name="studentnummer">001001</component>
<component name="achternaam">Bimans</component>
<component name="voorletters">L./component>
<component name="roepnaam">Leo</component>
<component name="geboortedatum">09-08-1986</component>
<component name="geslacht">V</component>
<component name="mobiel_telefoonnummer">0612345678</component>
<component name="voertaal_nl">Nederlands</component>
<component name="voertaal_en">Dutch</component>
<component name="extern_emailadres">L.Bimans@domain.nl</component>
</value>
<value type="structured">
<component name="studentnummer">001002</component>
<component name="achternaam">Boels</component>
<component name="voorletters">F.</component>
<component name="roepnaam">Felix</component>
<component name="geboortedatum">04-02-1993</component>
<component name="geslacht">M</component>
<component name="voertaal_nl">Nederlands</component>
<component name="voertaal_en">Dutch</component>
</value>
</attr>
应该翻译成:
<attr attr-name="items">
<value type="string">#studentnummer#001001#achternaam#Bimans#voorletters#L.#roepnaam#Leo#geboortedatum#09-08-1986#geslacht#V#mobiel_telefoonnummer#0612345678#voertaal_nl#Nederlands#voertaal_en#Dutch#extern_emailadres#L.Bimans@domain.nl></value>
<value type="string">#studentnummer#001002#achternaam#Boels#voorletters#F.#roepnaam#Felix#geboortedatum#04-02-1993#geslacht#M#voertaal_nl#Nederlands#voertaal_en#Dutch</value>
<attr>
另一个例子:
<attr attr-name="links">
<value type="structured">
<component name="rel">self</component>
<component name="href">http://192.83.206.98:9999/rds/basis/studenten/</component>
</value>
<value type="structured">
<component name="rel">edit</component>
<component name="href">http://192.83.206.98:9999/rds/basis/studenten/</component>
</value>
<value type="structured">
<component name="rel">describedby</component>
<component name="href">http://192.83.206.98:9999/rds/metadata-catalog/basis/studenten/</component>
</value>
</attr>
应该翻译成:
<attr attr-name="links">
<value type="string">#rel#self#href#http://192.83.206.98:9999/rds/basis/studenten/</value>
<value type="string">#rel#edit#href#http://192.83.206.98:9999/rds/basis/studenten/</value>
<value type="string">#rel#describedby#href#http://192.83.206.98:9999/rds/metadata-catalog/basis/studenten/</value>
</attr>
转换应尽可能通用。换句话说,相同的代码可以用于两种类型的输入数据(如果可能的话)。因此,没有对属性名称、值或任何内容的引用。 请注意,组件名称(来自结构)应该(最好)包含在结果字符串中(如示例所示),然后是实际值(全部由分隔符 # 分隔)。
一直在努力实现这一点,但到目前为止还没有运气。
还要注意我只能使用 xslt 1.0!
谢谢!
【问题讨论】:
-
展示你的最佳尝试总是有用的。然后我们可以看到你已经知道多少以及症结在哪里。
标签: xml xslt transformation