This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: scanning a tree (again)


On Sun, 3 Dec 2000 13:10:20 +0200
"Shlomi Sarfati" <shlomi@navixo.com> wrote:

Let's see if I understood you right. You have a XML tree which can contain <modified/> tags. If it does contain at least one of those tags, the result tree top element shall contain an attribute "modified" with value "true" and if not with value "false". Is that right?
If so, the following should do the job:

<xsl:template match="/">
    <newTopElement>

        <xsl:attribute name="modified">
            <xsl:choose>
                <xsl:when test="//modified">true</xsl:when>
                <xsl:otherwise>false</xsl:otherwise>
            </xsl:choose>
        </xsl:attribute>

    </newTopElement>
</xsl:template>

In fact, you could place the <xsl:attribute> part everywhere in your stylesheet. It will always add a "modified" attribute to the wrapping element with value "true" if the document contains <modified> tags, and "false" otherwise. If you change the value of the <xsl:when> "test" attribute you can check several part of the document for <modified> tags, as well.

Hope that helps,

Conny Krappatsch

> I am sorry for sending this question again but I didn't got the answer that
> I need maybe because I didn't explained my self !
> I need to run an xsl stylesheet on my xml tree that do the following :
> on every node in my xml tree I have a tag named 'modified' that tells me if
> the current node has been modified.
> I need to hold a flag that will tell me if one of the nodes has been
> modified !
> this flag will be the attribute of the first tag in my result tree. does it
> means that I need to check the source tree first
> for all the <modified> tags and then run my xsl (if so how should I do it
> ? )
> can you do something like this ?
> 
> 
> <xsl:variable name="valueofFlag"> false </xsl:variable>
> 
> 
> <xsl:template match="/">
> 	<head>
> 		<xsl:element name="menu">
> 			<xsl:attribute name="color">black</xsl:attribute>
> 			<xsl:apply-templates/>
> 			<xsl:attribute name="modified"> <xsl:copy-of select="$valueofFlag"/>
> </xsl:attribute>
> 		</xsl:element>
>  	</head>
> </xsl:template>
> 
> <xsl:template match="//child">
> 	<xsl:choose>
> 	   <xsl:when test ="//*[@modified='true']"> <xsl:variable
> name="valueofFlag"> true </xsl:variable>  </xsl:when>
> 	   <xsl:otherwise></xsl:otherwise>
> 	</xsl:choose>
> </xsl:template>
> 	.
> 	.
> 	.
> 	.
> 
> 
> this is example of my xml :
> 
> 
> <?xml version="1.0"?>
> <data_xml>
> 	  <list>
> 		<dynamic_menu_id>1003</dynamic_menu_id>
> 		<PARENT_ID>1003</PARENT_ID>
> 		<name>first child</name>
> 	      <position>1</position>
> 		<modified>true</modified>
> 		 <object>
> 		    <dynamic_menu_id>1004</dynamic_menu_id>
> 		    <object_name>Accounting</BUTTON_NAME>
> 		    <position>1</position>
>         	     <modified/>
> 		 </object>
> 	  	 <object>
> 		    <dynamic_menu_id>1005</dynamic_menu_id>
> 		    <object_name>management</BUTTON_NAME>
> 		    <position>2</position>
>         	     <modified/>
> 		 </object>
> 	  	 <object>
> 		    <dynamic_menu_id>1006</dynamic_menu_id>
> 		    <object_name>xxxx</BUTTON_NAME>
> 		    <position>3</position>
>         	     <modified/>
> 		 </object>
> 	  	 <object>
> 		    <dynamic_menu_id>1007</dynamic_menu_id>
> 		    <object_name>yyy</BUTTON_NAME>
> 		    <position>4</position>
>         	     <modified/>
> 		 </object>
> 	  </list>
> </data_xml>
> 
> 
> 
> 
> 
> 
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


-- 
______________________________________________________________________
Conny Krappatsch                              mailto:conny@smb-tec.com
SMB GmbH                                        http://www.smb-tec.com




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]