0

重複の可能性:
XSLT が属性の値に基づいてノードをグループ化できない

私には独特の状況があります。XSLT を使用して、ある XML を別の XML に変換しようとしています。ここに私のソースXMLがあります

<
<?xml version="1.0" encoding="windows-1252"?><XML>
    <Attributes>
    <Attribute><id>FW</id><Name>FamilyName</Name><Type>common</Type><Value>Footwear</Value></Attribute>
    <Attribute><id>83</id><Name>DepartmentName</Name><Type>common</Type><Value>Footwear</Value></Attribute>
    <Attribute><id>560</id><Name>GroupName</Name><Type>common</Type><Value>Men's Boots</Value></Attribute>
    <Attribute><id>5</id><Name>Buyer ID</Name><Type>common</Type><Value>Lee</Value></Attribute>
    <Attribute><id>331</id><Name>Enviornment</Name><Type>common</Type><Value>Development</Value></Attribute>
    <Attribute><id>79</id><Name>Retail</Name><Type>common</Type><Value></Value><Path>Data Attributes//Common Attributes//Vendor</Path></Attribute>
    <Attribute><id>1</id><Name>Media</Name><Type>common</Type><Value></Value><Path></Path></Attribute>
    <Attribute><id>402</id><Name>Gender</Name><Type>category</Type><Value>Men</Value><Path>Data Attributes//Category Specific//Toys/Infants//Gender</Path></Attribute>
    <Attribute><id>433</id><Name>HeelHeight</Name><Type>category</Type><Value></Value><Path>Data Attributes//Category Specific//Apparel//HeelHeight</Path></Attribute>
    <Attribute><id>909</id><Name>ShoeStyle</Name><Type>category</Type><Value>Boot</Value><Path>Data Attributes//Category Specific//Apparel//ShoeStyle</Path></Attribute>
    <Attribute><id>942</id><Name>Special Shoe Features</Name><Type>category</Type><Value>Waterproof</Value><Path>Data Attributes//Category Specific//Footwear//Special Shoe Features</Path></Attribute>
    <Attribute><id>1114</id><Name>Width</Name><Type>category</Type><Value>Medium</Value><Path>Data Attributes//Category Specific//Footwear//Width</Path></Attribute>
    <Attribute><id>41</id><Name>PlusShip</Name><Type>common</Type><Value>False</Value><Path></Path></Attribute>
    <Attribute><id>42</id><Name>IncShip</Name><Type>common</Type><Value>False</Value><Path></Path></Attribute>
    <Attribute><id>43</id><Name>Trademark/Registered Name</Name><Type>common</Type><Value>False</Value><Path>Data Attributes//Category Specific//Toys / Infants//Trademark/Registered Name</Path></Attribute>
    </Attributes>
</XML>

そして、これを次のxmlに変換するにはXSLが必要です

<?xml version="1.0" encoding="utf-8" ?> 
<Data Schema="XML A">
<Organization id="4" name="ABC">
<Catalog id="15" name="Product">
<Items>
<Item id="" shortname="4442 BLK" longname="4442 BLK" sku="Footwear" action="ADD" categorypath="Footwear/Footwear/Men's Boots" type="Product">
<Attributes type="Common">
<Attr id="" name="Buyer ID" path="" action="ADD" value="Lee" uom="" Locale="en_WW" /> 
<Attr id="" name="Enviornment" path="" action="ADD" value="Development" uom="" Locale="en_WW" />
<Attr id="" name="Retail" path="Data Attributes//Common Attributes//Vendor//VentureRetail//Retail" action="ADD" value="" uom="" Locale="en_WW" />
<Attr id="" name="Media" path="" action="ADD" value="" uom="" Locale="en_WW" />
<Attr id="" name="Vendor Model" path="Data Attributes//Common Attributes//SKU Details//VendorModel And GTINs//Vendor Model" action="ADD" value="4442 BLK" uom="" Locale="en_WW" />
<Attr id="" name="PlusShip" path="" action="ADD" value="False" uom="" Locale="en_WW" />
<Attr id="" name="IncShip" path="" action="ADD" value="False" uom="" Locale="en_WW" />
<Attr id="" name="Trademark/Registered Name" path="Data Attributes//Category Specific//Toys / Infants//Trademark/Registered Name" action="ADD" value="False" uom="" Locale="en_WW" />
</Attributes>
<Attributes type="Category">
<Attr id="" name="Gender" path="Data Attributes//Category Specific//Toys/Infants//Gender" action="ADD" value="Men" uom="" Locale="en_WW" />
<Attr id="" name="HeelHeight" path="Data Attributes//Category Specific//Apparel//HeelHeight" action="ADD" value="" uom="" Locale="en_WW" />
<Attr id="" name="ShoeStyle" path="Data Attributes//Category Specific//Apparel//ShoeStyle" action="ADD" value="Boot" uom="" Locale="en_WW" />
<Attr id="" name="Special Shoe Features" path="Data Attributes//Category Specific//Footwear//Special Shoe Features" action="ADD" value="Waterproof" uom="" Locale="en_WW" />
<Attr id="" name="Width" path="Data Attributes//Category Specific//Footwear//Width" action="ADD" value="Medium" uom="" Locale="en_WW" />
</Attributes>
<errorCodes>
  <errorCode>"value for Retail is missing."</errorCode> 
</errorCodes>
  </Item>
  </Items>
  </Catalog>
  </Organization>
  </Data>
>

ご覧のとおり、タイプに基づいて、すべての「共通」属性ノードを 1 つの属性ノードに配置しています。また、Attributes/Attribute/Name = 'Vendor Model' である Attributes/Attribute/Value から Items/item/@shortname を取得しています。longname と sku には同じ値が使用されます。これは、Name=FamilyName & Items/Item/@Vvalue で、Name=DepartmentName & Items/Item/@Value で、Name=GroupName の Items/Item/@value から Items/Item/@categorypath をプルしています。

部分的にこの形式に変換できます。ただし、Attr ノードを集約して、Attributes/@type に基づいて並べ替えることができません。

  <?xml version="1.0" encoding="utf-8" ?> 
- <Data Schema="XML A">
- <Organization id="4" name="ABC">
- <Catalog id="15" name="Product Staging">
- <Items>
- <Item id="" shortname="4442 BLK" longname="4442 BLK" sku="Footwear" action="ADD" categorypath="Footwear/Footwear/Men's Boots" type="Product">
- <Attributes type="Common">
  <Attr id="" name="Buyer ID" path="" action="ADD" value="Lee" uom="" Locale="en_WW" /> 
  </Attributes>
- <Attributes type="Common">
  <Attr id="" name="Enviornment" path="" action="ADD" value="Development" uom="" Locale="en_WW" /> 
  </Attributes>
- <Attributes type="Common">
  <Attr id="" name="Retail" path="Data Attributes//Common Attributes//Vendor//VentureRetail//Retail" action="ADD" value="" uom="" Locale="en_WW" /> 
  </Attributes>
- <Attributes type="Common">
  <Attr id="" name="Media" path="" action="ADD" value="" uom="" Locale="en_WW" /> 
  </Attributes>
- <Attributes type="Common">
  <Attr id="" name="Vendor Model" path="Data Attributes//Common Attributes//SKU Details//VendorModel And GTINs//Vendor Model" action="ADD" value="4442 BLK" uom="" Locale="en_WW" /> 
  </Attributes>
- <Attributes type="Category">
  <Attr id="" name="Gender" path="Data Attributes//Category Specific//Toys/Infants//Gender" action="ADD" value="Men" uom="" Locale="en_WW" /> 
  </Attributes>
- <Attributes type="Category">
  <Attr id="" name="HeelHeight" path="Data Attributes//Category Specific//Apparel//HeelHeight" action="ADD" value="" uom="" Locale="en_WW" /> 
  </Attributes>
- <Attributes type="Category">
  <Attr id="" name="ShoeStyle" path="Data Attributes//Category Specific//Apparel//ShoeStyle" action="ADD" value="Boot" uom="" Locale="en_WW" /> 
  </Attributes>
- <Attributes type="Category">
  <Attr id="" name="Special Shoe Features" path="Data Attributes//Category Specific//Footwear//Special Shoe Features" action="ADD" value="Waterproof" uom="" Locale="en_WW" /> 
  </Attributes>
- <Attributes type="Category">
  <Attr id="" name="Width" path="Data Attributes//Category Specific//Footwear//Width" action="ADD" value="Medium" uom="" Locale="en_WW" /> 
  </Attributes>
- <Attributes type="Common">
  <Attr id="" name="PlusShip" path="" action="ADD" value="False" uom="" Locale="en_WW" /> 
  </Attributes>
- <Attributes type="Common">
  <Attr id="" name="IncShip" path="" action="ADD" value="False" uom="" Locale="en_WW" /> 
  </Attributes>
- <Attributes type="Common">
  <Attr id="" name="Trademark/Registered Name" path="Data Attributes//Category Specific//Toys / Infants//Trademark/Registered Name" action="ADD" value="False" uom="" Locale="en_WW" /> 
  </Attributes>
- <Attributes type="Common">
  <Attr id="" name="Trademark/Registered Name" path="Data Attributes//Category Specific//Toys / Infants//Trademark/Registered Name" action="ADD" value="True" uom="" Locale="en_WW" /> 
  </Attributes>
- <errorCodes>
  <errorCode>"value for Retail is missing."</errorCode> 
  </errorCodes>
  </Item>
  </Items>
  </Catalog>
  </Organization>
  </Data>

前もって感謝します

4

0 に答える 0