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 Marc Ende <ml...@e-beyond.de> on 2009/12/01 10:39:20 UTC

xml with dots in tags

Hi,

since yesterday I've got a project on xslt transformation from one xml 
to another schema.
But within the source-xml they've got '.' in the tags. For example:

<root.element>
   <test.element>Hello World</test.element>
</root.element>

If I try to access the value with such xslt I got nothing:

<xsl:template match="/">
   <test><xsl:value-of select="root.element/test.element"/></test>
</xsl:template>

It I try it without dot's:
<root>
<test>Hello World</test>
</root>
and
<xsl:template match="/">
   <test><xsl:value-of select="root/test"/></test>
</xsl:template>

Everything works fine. I tried to escape the dots in the select with 
'\.' but that doesn't
work. In XPath there was the . mentioned as a replacement for a 
character. So it should
also work on '.' I think.

Does anybody has an idea?

By the way. Is there any way to 'copy' parts of one xml in the other xml 
within the transformation?
It would be helpful if there are parts which doesn't need to transformed 
(just copied).

Thanks for your help!

Marc

Re: xml with dots in tags

Posted by Michael Ludwig <mi...@gmx.de>.
Marc Ende schrieb am 01.12.2009 um 14:38:39 (+0100):
> Hi Michael,
> 
> thanks for your help. It seems that the issue doesn't relate to the
> '.'. But I have no further ideas. Can you have a look on this
> stylesheet and the input xml. I thought that the issue that the
> xsd:value-of doesn't provide any data relates to the dots. But now I
> know that's not the case.
> 
> Maybe you can give me a hint. I've spend about 8 hours and haven't
> found any point how I can resolve this issue.

Marc,

please reply to the list, not privately. (I know you did it
inadvertently, as this list does not set the Reply-To header
as it should.)

As to the issue at hand, it is dead simple. Your input is in a
namespace, and your stylesheet doesn't take that into account.
Read up about XML namespaces to save you from further harm and
waste of time. XML namespaces are trivial to understand, but a
bit annoying due to excessive URI verbosity.

<xmeldit.datenlieferung.1100 fassung="2009-07-31" version="1.5"
  produkt="OK.EWO" produkthersteller="AKDB" produktversion="05.70.10"
  xmlns="http://www.osci.de/xmeld15"
  xmlns:xoev="www.deutschland-online.de/XOEV"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.osci.de/xmeld15
  S:\e01entw_eGov\XMELD\XMELD1~1.5\xmeld-nachrichten-xmeldit.xsd">
  [...]

The URI for xoev does not look like a valid URI.

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

Your stylesheet should declare all namespaces that are needed and
use them accordingly.

<xsl:transform version="1.0"
  xmlns="http://www.osci.de/xmeld15"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

Plus, you *absolutely* need to learn about "push" vs "pull" approach.
You're using the pull approach, which is only suitable for the most
trivial tasks. The one you have looks like a job for a push approach.
The "modified identity template" approach I mentioned is a push
approach.

Good luck,
-- 
Michael Ludwig

Re: xml with dots in tags

Posted by Michael Ludwig <mi...@gmx.de>.
Marc Ende schrieb am 01.12.2009 um 10:39:20 (+0100):

> But within the source-xml they've got '.' in the tags. For example:
> 
> <root.element>
>   <test.element>Hello World</test.element>
> </root.element>

There's nothing unusual at all with that.

> If I try to access the value with such xslt I got nothing:
> 
> <xsl:template match="/">
>   <test><xsl:value-of select="root.element/test.element"/></test>
> </xsl:template>

Works fine for me. Did you apply the stylesheet to the correct input?

> I tried to escape the dots in the select with '\.' but that doesn't
> work.

It doesn't because you must not prefix the dot with a backslash. XPath
does not follow the same rules as grep, or the shell, or Perl.

> In XPath there was the . mentioned as a replacement for a character.
> So it should also work on '.' I think.

Don't know what you mean, but "." is the current context node.

> By the way. Is there any way to 'copy' parts of one xml in the other
> xml within the transformation?
> It would be helpful if there are parts which doesn't need to
> transformed (just copied).

I think you're looking for the standard pattern called "modified
identity transform". Googling for that will teach you the concept.
It's not difficult and really practical.

Best,
-- 
Michael Ludwig