You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Jason Rizer <ja...@yahoo.com> on 2002/01/12 23:47:00 UTC

XPATH Help

Hello,

I've just recently begun using xalan and I'm kind of
stuck on something
pretty simple.  I've worked through parts of a couple
of tutorials but 
I
still can't seem to handle this problem.  I'd like to
convert the
following chunk of xml:

<?xml version="1.0" encoding="UTF-8" ?>
<XMI xmlns:ABC="org.jason">
  <XMI.content>
    <ABC:jason.Smith>
      <LL/>
   </ABC:jason.Smith>
    <Smith/>
  <XMI content>
</XMI>

to this chunk:

<?xml version="1.0" encoding="UTF-8" ?>
<XMI xmlns:ABC="org.jason">
  <XMI.content>
    <ABC:Smith>
      <LL/>
   </ABC:Smith>
    <Smith/>
  <XMI content>
</XMI>

In other words I want to replace each elament named
jason.Smith with an
identical element (ie not affect any of it's children
or it's
attributes) named Smith but only when It occurs in the
Namespace ABC.  
I
think I need to use the XPATH namespace( ) function in
my match
expression but I can't quite seem to get it to work. 
Any help with
creating this stylesheet would be greatly appreciated.
 Thank in
advance!

-Jaso

__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

Re: XPATH Help

Posted by Jeff Turner <je...@socialchange.net.au>.
One way would be to create a default template which simply copies
everything across, and then override it in the case of elements called
ABC:jason.Smith.

Eg, here's the copy-everything bit:

---- copy-all.xsl ----

<?xml version="1.0"?>
<!--
This template copies all nodes it encounters, but at each node allows other
templates to match (unlike a copy-of from the root). 
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="child::node()|attribute::*">
		<xsl:copy>
			<xsl:for-each select="@*">
				<xsl:copy/>
			</xsl:for-each>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>


and here's a stylesheet that uses this, and renames one element:


<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:ABC="org.jason">
	<xsl:import href="copy-all.xsl"/>

	<xsl:template match="ABC:jason.Smith">
		<ABC:Smith>
			<xsl:apply-templates/>
		</ABC:Smith>
	</xsl:template>
</xsl:stylesheet>


That's adapted from Mike Kay's XSLT book (1st ed) in the <xsl:copy-of>
section.

HTH,

--Jeff


On Sat, Jan 12, 2002 at 02:47:00PM -0800, Jason Rizer wrote:
...
> In other words I want to replace each elament named
> jason.Smith with an identical element (ie not affect any of it's
> children or it's attributes) named Smith but only when It occurs in
> the Namespace ABC. 
...
> Any help with creating this stylesheet would be greatly appreciated.
> Thank in
> advance!
> 
> -Jaso
> 
> __________________________________________________
> Do You Yahoo!?
> Send FREE video emails in Yahoo! Mail!
> http://promo.yahoo.com/videomail/

RE: XPATH Help

Posted by Gary L Peskin <ga...@firstech.com>.
Jason --

Since this is a pure XSLT question and not specific to Xalan, you'll get
a faster response from the Mulberry list
(http://www.mulberrytech.com/xsl/xsl-list/index.html).  Have look over
there.

Gary

> -----Original Message-----
> From: Jason Rizer [mailto:jasonriz@yahoo.com] 
> Sent: Saturday, January 12, 2002 2:47 PM
> To: xalan-j-users@xml.apache.org
> Subject: XPATH Help
> 
> 
> Hello,
> 
> I've just recently begun using xalan and I'm kind of
> stuck on something
> pretty simple.  I've worked through parts of a couple
> of tutorials but 
> I
> still can't seem to handle this problem.  I'd like to
> convert the
> following chunk of xml:
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <XMI xmlns:ABC="org.jason">
>   <XMI.content>
>     <ABC:jason.Smith>
>       <LL/>
>    </ABC:jason.Smith>
>     <Smith/>
>   <XMI content>
> </XMI>
> 
> to this chunk:
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <XMI xmlns:ABC="org.jason">
>   <XMI.content>
>     <ABC:Smith>
>       <LL/>
>    </ABC:Smith>
>     <Smith/>
>   <XMI content>
> </XMI>
> 
> In other words I want to replace each elament named
> jason.Smith with an
> identical element (ie not affect any of it's children
> or it's
> attributes) named Smith but only when It occurs in the 
> Namespace ABC.  
> I
> think I need to use the XPATH namespace( ) function in
> my match
> expression but I can't quite seem to get it to work. 
> Any help with
> creating this stylesheet would be greatly appreciated.
>  Thank in
> advance!
> 
> -Jaso
> 
> __________________________________________________
> Do You Yahoo!?
> Send FREE video emails in Yahoo! Mail! 
> http://promo.yahoo.com/videomail/
>