[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re-insert IDs and RIDs

Subject: Re: Re-insert IDs and RIDs
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 20 Oct 2008 08:14:43 -0400
Re:  Re-insert IDs and RIDs
At 2008-10-20 09:31 +0530, J. S. Rawat wrote:
Have anybody any idea about how to re-insert IDs and RIDs as shown in the following example by xslt 2.0.

Not sure what aspect of the problem you are asking about. Below is a solution based on the limited evidence you've given ... I may have made incorrect assumptions regarding some properties of your vocabulary.


It would help next time if you specified what the nature of your question is so that those who try to help know where to advise.

I hope this helps.

. . . . . . . . . Ken

t:\ftemp>type rawat.xml
<doc>
<p> xxx <anchor rid="a5">key 1</anchor> ... <anchor rid="a8">key 2</anchor> xxx <anchor rid="a5">key 1</anchor> ... <anchor rid="a8">key 2</anchor></p>
<keys>
<key id="a5">key 1</key>
<key id="a8">key 2</key>
</keys>
</doc>


t:\ftemp>xslt2 rawat.xml rawat.xsl con
<?xml version="1.0" encoding="UTF-8"?><doc>
<para> xxx <x rid="x1">key 1</x> ... <x rid="x2">key 2</x> xxx <x rid="x1">key 1</x> ... <x rid="x2">key 2</x></para>
<items>
<item id="x1">key 1</item>
<item id="x2">key 2</item>
</items>
</doc>
t:\ftemp>type rawat.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">


<xsl:key name="ids" match="key" use="@id"/>

<!--map attributes-->
<xsl:template match="@rid | @id">
  <xsl:attribute name="{name(.)}">
    <xsl:for-each select="key('ids',.)">
      <xsl:text/>x<xsl:number/>
    </xsl:for-each>
  </xsl:attribute>
</xsl:template>

<!--map elements-->
<xsl:template match="p">
  <para><xsl:apply-templates select="@*|node()"/></para>
</xsl:template>

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

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

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

<!--identity for all other nodes-->
<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

t:\ftemp>



--
Upcoming XSLT/XSL-FO hands-on courses:      Wellington, NZ 2009-01
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video sample lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg
Video course overview:  http://www.youtube.com/watch?v=VTiodiij6gE
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.