XSLT1.0で配列を使用しているとスタックされています。私はXSLTで配列を使ったことが一度もありません。 Arrayに値を格納し、後で使用する必要があるという要件があります。 Infactは、私たちは、配列位置XSLTでの配列の値の保存と読み取り
に入力XMLを使用する必要が
<document>
<party>
<gtin>1000909090</gtin>
<pos>
<attrGroupMany name="temperatureInformation">
<row>
<attr name="temperatureCode">STORAGE</attr>
<attrQualMany name="temperature">
<value qual="FAH">10</value>
</attrQualMany>
<attrGroupMany name="temperatureStats">
<row>
<attr name="StatsCode">CODE1</attr>
</row>
<row>
<attr name="StatsCode">CODE2</attr>
</row>
</attrGroupMany>
</row>
<row>
<attr name="temperatureCode">HANDLING</attr>
<attrQualMany name="temperature">
<value qual="FAH">30</value>
</attrQualMany>
<attrGroupMany name="temperatureStats">
<row>
<attr name="StatsCode">CODE3</attr>
</row>
<row>
<attr name="StatsCode">CODE4</attr>
</row>
</attrGroupMany>
</row>
</attrGroupMany>
</pos>
</party>
</document>
予想される出力は、私は以下のXSLTを使用しています
<?xml version="1.0" encoding="UTF-8"?>
<CatalogItem>
<RelationshipData>
<Relationship>
<RelationType>temperatureInformation_details</RelationType>
<RelatedItems>
<RelatedItem referenceKey="temperatureInformation_details-STORAGE-temperature-FAH-10-1" />
<RelatedItem referenceKey="temperatureInformation_details-HANDLING-temperature-FAH-30-2" />
</RelatedItems>
</Relationship>
<Relationship>
<RelationType>temperatureStats</RelationType>
<RelatedItems>
<RelatedItem referenceKey="temperatureStats-CODE1-1-1">
<Attribute name="temperatureInformationreferenceKey">temperatureInformation_details-STORAGE-temperature-FAH-10-1"</Attribute>
</RelatedItem>
<RelatedItem referenceKey="temperatureStats-CODE2-2-1">
<Attribute name="temperatureInformationreferenceKey">temperatureInformation_details-STORAGE-temperature-FAH-10-1"</Attribute>
</RelatedItem>
<RelatedItem referenceKey="temperatureStats-CODE3-1-2">
<Attribute name="temperatureInformationreferenceKey">temperatureInformation_details-HANDLING-temperature-FAH-30-2</Attribute>
</RelatedItem>
<RelatedItem referenceKey="temperatureStats-CODE4-2-2">
<Attribute name="temperatureInformationreferenceKey">temperatureInformation_details-HANDLING-temperature-FAH-30-2</Attribute>
</RelatedItem>
</RelatedItems>
</Relationship>
</RelationshipData>
</CatalogItem>
です。私は最初の配列に値を格納し、2番目の配列に値を格納するコード以外のコードを書いています。
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="document">
<CatalogItem>
<RelationshipData>
<Relationship>
<RelationType>temperatureInformation_details</RelationType>
<RelatedItems>
<xsl:for-each select="party/pos/attrGroupMany[@name ='temperatureInformation']/row">
<RelatedItem>
<xsl:attribute name="referenceKey">
<xsl:value-of select="concat('temperatureInformation_details','-',attr[@name='temperatureCode'],'-',attrQualMany/@name,'-',attrQualMany/value/@qual,'-',attrQualMany/value,'-', position() )"/>
</xsl:attribute>
</RelatedItem>
</xsl:for-each>
</RelatedItems>
</Relationship>
<Relationship>
<RelationType>temperatureStats</RelationType>
<RelatedItems>
<xsl:for-each select="party/pos/attrGroupMany[@name ='temperatureInformation']/row">
<xsl:variable name="v_temperatureInformation_position" select="position()"/>
<xsl:for-each select="attrGroupMany[@name ='temperatureStats']/row">
<RelatedItem>
<xsl:attribute name="referenceKey">
<xsl:value-of select="concat('temperatureStats','-',attr[@name='StatsCode'],'-', position(),'-', $v_temperatureInformation_position )"/>
</xsl:attribute>
<Attribute name="temperatureInformationreferenceKey">
<xsl:value-of select="'Dummy'"/>
<!-- Not sure of XSLT code here but the pseudo code does like this
If v_temperatureInformation_position = 1
Select
The first value of reference key of temperatureInformation_details stored in array
If v_temperatureInformation_position = 2
Select
The second value of reference key of temperatureInformation_details stored in array
If v_temperatureInformation_position = 3
Select
The third value of reference key of temperatureInformation_details stored in array
And so on.. -->
</Attribute>
</RelatedItem>
</xsl:for-each>
</xsl:for-each>
</RelatedItems>
</Relationship>
</RelationshipData>
</CatalogItem>
</xsl:template>
</xsl:stylesheet>
XSLT 1.0または2.0には配列がありませんので、入出力変換に関して達成したいことを説明する必要があります。 –
@Martin:どうにかして最初のループの値を保存し、それを2番目のループで使用する必要があります。私は既に入力と出力のXMLを言及している – Victor