Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 8th, 2011, 11:50 AM
Authorized User
Points: 310, Level: 6
Points: 310, Level: 6 Points: 310, Level: 6 Points: 310, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default Swapping values between Element Name and documentation

Here is an XML
INPUT
------------------
<xsd:element name="SAPIdocRelease" minOccurs="0">
<xsd:annotation>
<xsd:documentation>DOCREL</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="4"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>

OUTPUT
--------------

<xsd:element name="DOCREL" minOccurs="0">
<xsd:annotation>
<xsd:documentation>SAPIdocRelease</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="4"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>

"DOCREL" needs to swapped wth "SAPIdocRelease" in generic way.

I have so many fields like that in one file. Doing manually taking longer than expected with cut & paste. Is there a generic way to swap those 2 fields with the exact same structure?

Appreciated in advance
Reply With Quote
  #2 (permalink)  
Old February 8th, 2011, 11:53 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,133
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Generic way?

What have you tried so far?
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
  #3 (permalink)  
Old February 8th, 2011, 11:56 AM
Authorized User
Points: 310, Level: 6
Points: 310, Level: 6 Points: 310, Level: 6 Points: 310, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I need to work on different names in file. So i like to have something with standard xslt conversion with out names of the values mentioned.

I just started working on it with no idea on how to.
Reply With Quote
  #4 (permalink)  
Old February 8th, 2011, 12:00 PM
Friend of Wrox
Points: 6,648, Level: 34
Points: 6,648, Level: 34 Points: 6,648, Level: 34 Points: 6,648, Level: 34
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,238
Thanks: 0
Thanked 244 Times in 243 Posts
Default

Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  version="1.0">

  <xsl:template match="@* | node()">
    <xsl:copy>
       <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="xsd:element/@name">
    <xsl:attribute name="{name()}">
       <xsl:value-of select="../xsd:annotation/xsd:documentation"/>
    </xsl:attribute>
  </xsl:template>

  <xsl:template match="xsd:element/xsd:annotation/xsd:documentation">
    <xsl:copy>
       <xsl:value-of select="../../@name"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
Untested but should give you an idea.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
  #5 (permalink)  
Old February 8th, 2011, 12:09 PM
Authorized User
Points: 310, Level: 6
Points: 310, Level: 6 Points: 310, Level: 6 Points: 310, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are genius Martin. Works like a charm. Thanks a bunch
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining restrictions based on element/attribute values aldwinenriquez XML 3 May 13th, 2009 03:55 AM
XML element with delimited values and XSLT Clark Kent XSLT 15 May 7th, 2008 10:10 AM
xml element values vakorde XSLT 3 May 2nd, 2006 04:36 AM
Swapping Images software_developer_kk Javascript How-To 1 April 13th, 2005 10:00 AM
Update a table with XML element values alavastros XML 1 July 16th, 2004 11:36 PM



All times are GMT -4. The time now is 07:14 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.