XSLT将一些元素转换为属性并按属性值排序

时间:2011-03-16 17:58:05

标签: xslt xslt-grouping

  

可能重复:
  XSLT unable to group nodes based on attribute's value

我有一个独特的情况。我正在尝试使用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>

我需要XSL将其转换为以下xml

<?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>
>

正如您所看到的那样,它将所有“Common”Attr节点放在一个属性节点中。 它还从Attributes / Attribute / Value中提取Items / item / @ shortname,其中Attributes / Attribute / Name ='Vendor Model'。 longname和amp;使用相同的值。 SKU。 它从Items / Item / @值中提取Items / Item / @ categorypath,其中Name = FamilyName&amp; Items / Item / @ Vvalue,其中Name = DepartmentName&amp; Items / Item / @ Value其中Name = GroupName。

我可以将其部分转换为此格式。但是无法聚合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>

先谢谢

0 个答案:

没有答案