xsl-list
[Top] [All Lists]

Re: [xsl] xpath query

2008-01-19 09:39:02
Thank you all.

I was thinking last night, typically I just output an html file to see
the results of my transformation.
Then I thought what if I just wanted to process the original xml file,
replace the apply="1" with apply="true" and write the results to
another xml file
I read elsewhere in the archives about the identity template and the
suggestion is basically the following (to just replicate the original
xml)
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">
<xsl:output method="xml" indent="yes"/>
   <xsl:template match="@* | node()">
       <xsl:copy>
           <xsl:apply-templates select="@* | node()"/>
       </xsl:copy>
   </xsl:template>
</xsl:stylesheet>

Which works as advertised.
I understand that I can create another template to match what ever I
like to futrher refine the output like this

 <xsl:template match="@apply">
       <xsl:attribute name="apply">
           <xsl:value-of select="replace(., '1', 'true')"/>
       </xsl:attribute>
   </xsl:template>

So far so good.
I have 2 questions though.
1) - In the first template that copies the original xml, the
expression select="@* | node()" What is this saying?
I read it is another way of phrasing this select="attribute() |
element() | text() | comment() | processing-instruction()" (which
seems much clearer)
Either expression does what I want, but I am trying to map the first
expression "@* | node()" onto the latter.
I am pretty sure the @* means all attributes?  If this is the case how
does "node()" translate to "element() | text() | comment() |
processing-instruction()"?

2) - Also related to the first template. Why do I need the
<xsl:template match="@* | node()"> and
<xsl:apply-templates select="@* | node()"/> in the <xsl:copy/> tag?
I would have thought in the template match "/" would have sufficed.
(When I try that, I just get the values from the nodes).

Also in the thread Abel stated
I think many people find this at first confusing: when do you get a node
set, when do you get one node, when do you get a sequence or a sequence
of nodes, when do you need apply-templates, when for-each or
for-each-group etc etc. Getting it straight is vital for working with
XSLT without frustration.

Do you know of any resources, either online or in print that explain
these concepts well with good examples?  I would really like to make
this confusion
a thing of the past for myself.
Thanks in advance
Sean

On Jan 19, 2008 8:21 AM, Abel Braaksma <abel(_dot_)online(_at_)xs4all(_dot_)nl> 
wrote:
Sean Tiley wrote:
Hi Abel,
No I am not the same person. Why did you think that?


The first part of the OP's name is 'Sen', yours is "Sean". Also, it
happens sometimes that people use different email addresses to anonymize
their posts, but sometimes forget it and send from their other address.
And of course, companies may share addresses with people through groups
(but then it's not the same p).

I was reading the thread and was trying to fully understand the
requirement and solutions provided. I used the original XML to play
with creating my stylesheets to see what I could do with it.


That's very good, that was the way I learned XSLT: reading from the list
and trying to understand what was posted.

Did I do something incorrect when I asked my questions in the same
thread?  Should I have posted a new message.  Please tell me as I am
new to this list and dont want to make a bad impression.


No and not necessarily, but Tommie already explained you that ;)
I was just a bit puzzled by your follow-up questions and didn't see
something like "I read this thread and was wondering about...". So it
"sounded" as if it was the OP (Original Poster) asking follow-ups...

I do appreciate your comments on my questions, they certainly help me
get all of this straight in my head.


Glad to have been of help. Ask anytime, this is a lively list and we're
here to help ;)


Cheers,
-- Abel Braaksma

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



-- 
Sean Tiley
sean(_dot_)tiley(_at_)gmail(_dot_)com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>