|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] AW: Renaming One Element in a XML document using XSL
Hi Sian,
Here is a possible solution for your problem.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2004/07/xpath-functions"
xmlns:xdt="http://www.w3.org/2004/07/xpath-datatypes">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="node() | @*">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Height | Width">
<xsl:element name="{concat(substring-before(local-name(parent::*), 'Image'),
local-name())}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
This Stylesheet is giving you the followign output after transforming your
input document:
<?xml version="1.0" encoding="UTF-8"?>
<ItemSearchResponse>
<OperationRequest>
<HTTPHeaders>
<Header/>
</HTTPHeaders>
<RequestId>187MFFZ905VXM20D1H6J</RequestId>
<Arguments>
<Argument Name="Service" Value="AWSECommerceService"/>
</Arguments>
<RequestProcessingTime>0.546659946</RequestProcessingTime>
</OperationRequest>
<Items>
<Request>
<IsValid>True</IsValid>
<ItemSearchRequest>
<Power>title:Harry Potter</Power>
<ResponseGroup>Large</ResponseGroup>
<SearchIndex>Books</SearchIndex>
<Sort>salesrank</Sort>
</ItemSearchRequest>
</Request>
<TotalResults>717</TotalResults>
<TotalPages>72</TotalPages>
<Item>
<ASIN>0747581088</ASIN>
<DetailPageURL> </DetailPageURL>
<SalesRank>1</SalesRank>
<SmallImage>
<URL>http://images.amazon.com/images/P/0747581088.02._SCTHUMB
ZZZ_.jpg</URL>
<SmallHeight>75</SmallHeight>
<SmallWidth>53</SmallWidth>
</SmallImage>
<MediumImage>
<URL>http://images.amazon.com/images/P/0747581088.02._SCMZZZZ
ZZZ_.jpg</URL>
<MediumHeight>160</MediumHeight>
<MediumWidth>113</MediumWidth>
</MediumImage>
<LargeImage>
<URL>http://images.amazon.com/images/P/0747581088.02._SCLZZZZ
ZZZ_.jpg</URL>
<LargeHeight>500</LargeHeight>
<LargeWidth>352</LargeWidth>
</LargeImage>
</Item>
</Items>
</ItemSearchResponse>
HTH
wbr,
Roman
> -----Urspr|ngliche Nachricht-----
> Von: Sian Mace [mailto:sianmace@xxxxxxxxxxx]
> Gesendet: Mittwoch, 2. Februar 2005 15:02
> An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Betreff: Renaming One Element in a XML document using XSL
>
> HI,
>
>
>
> I am using Amazon web services and asp.net for a university project.
>
>
>
> Im getting the xml back from the web service, but when trying
> to load in to asp.net dataset I get problems because
> Microsoft cannot support XML fully yet.
>
>
>
> This is because the xml returned has element names the same
> in different places.
>
>
>
> What I need to do is to get the whole dataset, which is quite
> massive, and just rename the rogue elements to something to
> make them unique.
>
>
>
> Here are the code and examples of what I want.
>
>
>
> <ItemSearchResponse>
>
> <OperationRequest>
>
> <HTTPHeaders>
>
> <Header ></Header>
>
> </HTTPHeaders>
>
> <RequestId>187MFFZ905VXM20D1H6J</RequestId>
>
> <Arguments>
>
> <Argument Name="Service"
> Value="AWSECommerceService"></Argument>
>
> </Arguments>
>
>
> <RequestProcessingTime>0.546659946</RequestProcessingTime>
>
> </OperationRequest>
>
> <Items>
>
> <Request>
>
> <IsValid>True</IsValid>
>
> <ItemSearchRequest>
>
>
> <Power>title:Harry Potter</Power>
>
> <ResponseGroup>Large</ResponseGroup>
>
>
> <SearchIndex>Books</SearchIndex>
>
>
> <Sort>salesrank</Sort>
>
> </ItemSearchRequest>
>
> </Request>
>
> <TotalResults>717</TotalResults>
>
> <TotalPages>72</TotalPages>
>
> <Item>
>
> <ASIN>0747581088</ASIN>
>
> <DetailPageURL> </DetailPageURL>
>
> <SalesRank>1</SalesRank>
>
> <SmallImage>
>
>
> <URL>http://images.amazon.com/images/P/0747581088.02._SCTHUMBZ
> ZZ_.jpg</URL>
>
> <Height>75</Height>
>
> <Width>53</Width>
>
> </SmallImage>
>
> <MediumImage>
>
>
> <URL>http://images.amazon.com/images/P/0747581088.02._SCMZZZZZ
> ZZ_.jpg</URL>
>
> <Height>160</Height>
>
> <Width>113</Width>
>
> </MediumImage>
>
> <LargeImage>
>
>
> <URL>http://images.amazon.com/images/P/0747581088.02._SCLZZZZZ
> ZZ_.jpg</URL>
>
> <Height>500</Height>
>
> <Width>352</Width>
>
> </LargeImage>
>
> </Item>
>
> </Items>
>
> </ItemSearchResponse>
>
>
>
> There is the a Height element (and width) in SmallImage,
> LargeImage and Medium Image, And .Net Datasets cannot deal with this.
>
> So I need to convert this to something like SmallHeight,
> MediumHeight ect.
>
>
>
> So I want to copy all the document and rename certain nodes.
> How can I do this??
>
>
>
> Any help would be greatly appreciated
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








