Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Tue, 27 May 2008 19:58:01 -0700,    group: microsoft.public.xml        back       


XSL HELP!!   
Hello,
I have a XMl as below:

*******************
<?xml version="1.0" ?> 
<p1:Domains_and_Emails xmlns:p1="LDAP">
  <Organization>ABCD</Organization>
  <Radius Suspended="false" ID="1" Platform_Id="7" 
ObjectClass="radiusprofile">
    <Common_Name>OptiUser</Common_Name>
    <radiusProfileDn>cn=dialup,ou=radiusprofiles,o=ABCD</radiusProfileDn>
  </Radius>
  <Domain Suspended="false" ID="2" Platform_Id="7">
    <Organization_Unit>domains</Organization_Unit>
    <domain_name>xyztel.com</domain_name>

    <UnixEmail Suspended="false" ID="3" Platform_Id="7" 
ObjectClass="radiusprofile,posixAccount,CourierMailAccount">
      <uid>info</uid>
      <Password>xyz</Password>
      <EmailAccount>info@xyztel.com</EmailAccount>
    </UnixEmail>

    <UnixEmail Suspended="false" ID="4" Platform_Id="7" 
ObjectClass="radiusprofile,posixAccount,CourierMailAccount">
      <uid attributeId="1">jeff</uid>
      <Password attributeId="4">xyz</Password>
      <EmailAccount>jeff@xyztel.com</EmailAccount>
    </UnixEmail>

    <UnixEmail Suspended="false" ID="72" Platform_Id="7" 
ObjectClass="radiusprofile,posixAccount,CourierMailAccount">
      <uid attributeId="1">ff</uid>
      <Password attributeId="4">xyz</Password>
      <EmailAccount>ff@xyztel.com</EmailAccount>
    </UnixEmail>

  </Domain>

</p1:Domains_and_Emails>
*******************

Using a XSL template, how to get ONLY the node UnixEmail with attribute ID 
value = 4 PLUS ALL OTHER NODES (such as  <Organization>)

Thanks,
Ganesh
date: Tue, 27 May 2008 19:58:01 -0700   author:   Ganesh Muthuvelu

Re: XSL HELP!!   
Ganesh Muthuvelu wrote:

> Using a XSL template, how to get ONLY the node UnixEmail with attribute ID 
> value = 4 PLUS ALL OTHER NODES (such as  <Organization>)

Here is a sample stylesheet:

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

   <xsl:param name="id" select="4"/>

   <xsl:output method="xml"/>

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

   <xsl:template match="UnixEmail">
     <xsl:if test="@ID = $id">
       <xsl:copy-of select="."/>
     </xsl:if>
   </xsl:template>

</xsl:stylesheet>


Result with your XML sample is

<p1:Domains_and_Emails xmlns:p1="LDAP">
   <Organization>ABCD</Organization>
   <Radius Suspended="false" ID="1" Platform_Id="7" 
ObjectClass="radiusprofile">
     <Common_Name>OptiUser</Common_Name>
     <radiusProfileDn>cn=dialup,ou=radiusprofiles,o=ABCD</radiusProfileDn>
   </Radius>
   <Domain Suspended="false" ID="2" Platform_Id="7">
     <Organization_Unit>domains</Organization_Unit>
     <domain_name>xyztel.com</domain_name>



     <UnixEmail Suspended="false" ID="4" Platform_Id="7" 
ObjectClass="radiusprofile,posixAccount,CourierMailAccount">
       <uid attributeId="1">jeff</uid>
       <Password attributeId="4">xyz</Password>
       <EmailAccount>jeff@xyztel.com</EmailAccount>
     </UnixEmail>



   </Domain>

</p1:Domains_and_Emails>


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Wed, 28 May 2008 13:07:57 +0200   author:   Martin Honnen

Re: XSL HELP!!   
Martin,
Thanks for your help. I have one question on this. Is it possible to have a 
variable name for the template "match"?.
The reason I am asking this is: The node "UnixEmail" is NOT static and may 
change dynamically, for example, it could be even the "Domain" node..

So, is it possible to have something like this n XSL:?

<xsl:template match=@DynamicNodeName>

Thanks,
Ganesh


"Martin Honnen" wrote:

> Ganesh Muthuvelu wrote:
> 
> > Using a XSL template, how to get ONLY the node UnixEmail with attribute ID 
> > value = 4 PLUS ALL OTHER NODES (such as  <Organization>)
> 
> Here is a sample stylesheet:
> 
> <xsl:stylesheet
>    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>    version="1.0">
> 
>    <xsl:param name="id" select="4"/>
> 
>    <xsl:output method="xml"/>
> 
>    <xsl:template match="@* | node()">
>      <xsl:copy>
>        <xsl:apply-templates select="@* | node()"/>
>      </xsl:copy>
>    </xsl:template>
> 
>    <xsl:template match="UnixEmail">
>      <xsl:if test="@ID = $id">
>        <xsl:copy-of select="."/>
>      </xsl:if>
>    </xsl:template>
> 
> </xsl:stylesheet>
> 
> 
> Result with your XML sample is
> 
> <p1:Domains_and_Emails xmlns:p1="LDAP">
>    <Organization>ABCD</Organization>
>    <Radius Suspended="false" ID="1" Platform_Id="7" 
> ObjectClass="radiusprofile">
>      <Common_Name>OptiUser</Common_Name>
>      <radiusProfileDn>cn=dialup,ou=radiusprofiles,o=ABCD</radiusProfileDn>
>    </Radius>
>    <Domain Suspended="false" ID="2" Platform_Id="7">
>      <Organization_Unit>domains</Organization_Unit>
>      <domain_name>xyztel.com</domain_name>
> 
> 
> 
>      <UnixEmail Suspended="false" ID="4" Platform_Id="7" 
> ObjectClass="radiusprofile,posixAccount,CourierMailAccount">
>        <uid attributeId="1">jeff</uid>
>        <Password attributeId="4">xyz</Password>
>        <EmailAccount>jeff@xyztel.com</EmailAccount>
>      </UnixEmail>
> 
> 
> 
>    </Domain>
> 
> </p1:Domains_and_Emails>
> 
> 
> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/
>
date: Wed, 28 May 2008 06:43:01 -0700   author:   Ganesh Muthuvelu

Re: XSL HELP!!   
Ganesh Muthuvelu wrote:

> Thanks for your help. I have one question on this. Is it possible to have a 
> variable name for the template "match"?.
> The reason I am asking this is: The node "UnixEmail" is NOT static and may 
> change dynamically, for example, it could be even the "Domain" node..
> 
> So, is it possible to have something like this n XSL:?
> 
> <xsl:template match=@DynamicNodeName>

No, that is not possible. With XSLT 1.0 you are not even allowed to use 
variables in match pattersn.

With XSLT 2.0 you could use
   <xsl:param name="element-name" select="'UnixEmail'"/>

   <xsl:template match="*[local-name() eq $element-name]">

There are currently three XSLT 2.0 processors, Saxon 9, AltovaXML, and 
Gestalt.


With XSLT 1.0 you need to check inside of your template e.g.
   <xsl:template match="*">
     <xsl:choose>
       <xsl:when test="local-name() = $element-name">


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Wed, 28 May 2008 16:07:43 +0200   author:   Martin Honnen

Re: XSL HELP!!   
Thanks again.. This XSL does not produce the same result - I am trying to use 
a variable for the element "UnixEmail". What's wrong?. Thanks.

******************
<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">

   <xsl:param name="id" select="4"/>
   <xsl:param name="element-name" select="UnixEmail"/>

   <xsl:output method="xml"/>

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

<xsl:template match="*">
     <xsl:choose>
       <xsl:when test="local-name() = $element-name">
     	<xsl:if test="@ID = $id">
       	<xsl:copy-of select="."/>
     	</xsl:if>
       </xsl:when>
       <xsl:otherwise>
       	<xsl:copy-of select="."/>
       </xsl:otherwise>
</xsl:choose>
   </xsl:template>
</xsl:stylesheet>
******************

"Martin Honnen" wrote:

> Ganesh Muthuvelu wrote:
> 
> > Thanks for your help. I have one question on this. Is it possible to have a 
> > variable name for the template "match"?.
> > The reason I am asking this is: The node "UnixEmail" is NOT static and may 
> > change dynamically, for example, it could be even the "Domain" node..
> > 
> > So, is it possible to have something like this n XSL:?
> > 
> > <xsl:template match=@DynamicNodeName>
> 
> No, that is not possible. With XSLT 1.0 you are not even allowed to use 
> variables in match pattersn.
> 
> With XSLT 2.0 you could use
>    <xsl:param name="element-name" select="'UnixEmail'"/>
> 
>    <xsl:template match="*[local-name() eq $element-name]">
> 
> There are currently three XSLT 2.0 processors, Saxon 9, AltovaXML, and 
> Gestalt.
> 
> 
> With XSLT 1.0 you need to check inside of your template e.g.
>    <xsl:template match="*">
>      <xsl:choose>
>        <xsl:when test="local-name() = $element-name">
> 
> 
> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/
>
date: Wed, 28 May 2008 07:48:00 -0700   author:   Ganesh Muthuvelu

Re: XSL HELP!!   
Ganesh Muthuvelu wrote:
> Thanks again.. This XSL does not produce the same result - I am trying to use 
> a variable for the element "UnixEmail". What's wrong?. Thanks.
> 
> ******************
> <xsl:stylesheet
>    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>    version="1.0">
> 
>    <xsl:param name="id" select="4"/>
>    <xsl:param name="element-name" select="UnixEmail"/>

You need to assign a string value e.g.
      <xsl:param name="element-name" select="'UnixEmail'"/>


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Wed, 28 May 2008 18:14:32 +0200   author:   Martin Honnen

Re: XSL HELP!!   
Martin,
Thanks, I did that.. but still I do not get the desired result.. Could you 
help?

regards,
Ganesh

"Martin Honnen" wrote:

> Ganesh Muthuvelu wrote:
> > Thanks again.. This XSL does not produce the same result - I am trying to use 
> > a variable for the element "UnixEmail". What's wrong?. Thanks.
> > 
> > ******************
> > <xsl:stylesheet
> >    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >    version="1.0">
> > 
> >    <xsl:param name="id" select="4"/>
> >    <xsl:param name="element-name" select="UnixEmail"/>
> 
> You need to assign a string value e.g.
>       <xsl:param name="element-name" select="'UnixEmail'"/>
> 
> 
> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/
>
date: Wed, 28 May 2008 09:28:00 -0700   author:   Ganesh Muthuvelu

Re: XSL HELP!!   
Ganesh Muthuvelu wrote:

> Thanks, I did that.. but still I do not get the desired result.. Could you 
> help?

Your template for elements needs to make sure it follows the identity 
transformation approach by doing a shallow copy with xsl:copy and by 
processing the attributes and child nodes:

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

    <xsl:param name="id" select="4"/>
    <xsl:param name="element-name" select="'UnixEmail'"/>

    <xsl:output method="xml"/>

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

<xsl:template match="*">
      <xsl:choose>
        <xsl:when test="local-name() = $element-name">
         <xsl:if test="@ID = $id">
        	  <xsl:copy-of select="."/>
         </xsl:if>
        </xsl:when>
        <xsl:otherwise>
        	<xsl:copy>
           <xsl:apply-templates select="@* | node()"/>
         </xsl:copy>
        </xsl:otherwise>
       </xsl:choose>
</xsl:template>
</xsl:stylesheet>


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Wed, 28 May 2008 18:42:20 +0200   author:   Martin Honnen

Re: XSL HELP!!   
Martin,
I found it.. This is the right XSL to use.. thanks for all your help. You 
are the best!

***************************************
<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">

   <xsl:param name="id" select="4"/>
   <xsl:param name="element-name" select="'UnixEmail'"/>

   <xsl:output method="xml"/>

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

<xsl:template match="@*|node()">
     <xsl:choose>
       <xsl:when test="local-name() = $element-name">
     	<xsl:if test="@ID = $id">
       	<xsl:copy-of select="."/>
     	</xsl:if>
       </xsl:when>
       <xsl:otherwise>
       	<xsl:copy>
	  <xsl:apply-templates select="@*|node()"/>
	</xsl:copy>
       </xsl:otherwise>
</xsl:choose>
   </xsl:template>
</xsl:stylesheet>

************************************



"Ganesh Muthuvelu" wrote:

> Martin,
> Thanks, I did that.. but still I do not get the desired result.. Could you 
> help?
> 
> regards,
> Ganesh
> 
> "Martin Honnen" wrote:
> 
> > Ganesh Muthuvelu wrote:
> > > Thanks again.. This XSL does not produce the same result - I am trying to use 
> > > a variable for the element "UnixEmail". What's wrong?. Thanks.
> > > 
> > > ******************
> > > <xsl:stylesheet
> > >    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > >    version="1.0">
> > > 
> > >    <xsl:param name="id" select="4"/>
> > >    <xsl:param name="element-name" select="UnixEmail"/>
> > 
> > You need to assign a string value e.g.
> >       <xsl:param name="element-name" select="'UnixEmail'"/>
> > 
> > 
> > -- 
> > 
> > 	Martin Honnen --- MVP XML
> > 	http://JavaScript.FAQTs.com/
> >
date: Wed, 28 May 2008 09:44:00 -0700   author:   Ganesh Muthuvelu

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us