match if an attribute has a value, or is not available.

match if an attribute has a value, or is not available.

Post by Phli » Mon, 07 Jul 2003 02:04:16



XMLers:

I'm writing an XSLT to filter XML into XML. The source has many languages,
and the target only one.

If a node has no language, I need it copied in, not excluded.

Here's the sample XML:

 <?xml version="1.0"?>
 <gloss>
  <note>has no language, so this remains</note>
  <verbiage xml:lang="EN">dog</verbiage>
  <verbiage xml:lang="ES">perro</verbiage>
  <verbiage xml:lang="PT">cao</verbiage>
 </gloss>

Here's the filter:

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

  <xsl:copy>

  </xsl:copy>
   </xsl:template>


 </xsl:stylesheet>

I need the equivalent of the function attribute-available(). Other
permutations of this filter naturally result in no nodes in the output XML.

--
  Phlip
    http://www.c2.com/cgi/wiki?TestFirstUserInterfaces

 
 
 

match if an attribute has a value, or is not available.

Post by Dimitre Novatche » Mon, 07 Jul 2003 02:53:19




>  </xsl:stylesheet>

> I need the equivalent of the function attribute-available(). Other
> permutations of this filter naturally result in no nodes in the output XML


or


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

 
 
 

match if an attribute has a value, or is not available.

Post by Phli » Mon, 07 Jul 2003 03:23:02



> or


Thanks, but (given 'xsltproc oneLang.xslt manyLang.xml'), the second returns
only tags with no xml:lang at all, and the first returns no nodes
whatsoever.

(Using libxml 20507, libxslt 10030 and libexslt 720
xsltproc was compiled against libxml 20507, libxslt 10030 and libexslt 720
libxslt 10030 was compiled against libxml 20507
libexslt 720 was compiled against libxml 20507)

BTW I have solved my outer problem with this script:

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

    <xsl:copy>
      <xsl:apply-templates


    </xsl:copy>
  </xsl:template>
 </xsl:stylesheet>

But it's still not as minimal as I would have liked. One uses it like this:

 xsltproc --param copy-lang "'es'" oneLang.xslt manyLang.xml

--
  Phlip
    http://www.c2.com/cgi/wiki?TestFirstUserInterfaces

 
 
 

match if an attribute has a value, or is not available.

Post by Dimitre Novatche » Mon, 07 Jul 2003 04:54:06




> > or


> Thanks, but (given 'xsltproc oneLang.xslt manyLang.xml'), the second
returns
> only tags with no xml:lang at all, and the first returns no nodes
> whatsoever.

I cannot reproduce this. With 8 different XSLT processors and with this
transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>

  <xsl:template match="/">




  </xsl:template>
</xsl:stylesheet>

when applied on your source.xml:

<gloss>
  <note>has no language, so this remains</note>
  <verbiage xml:lang="EN">dog</verbiage>
  <verbiage xml:lang="ES">perro</verbiage>
  <verbiage xml:lang="PT">cao</verbiage>
</gloss>

The same (wanted) result is produced:


   <note>has no language, so this remains</note><verbiage
xml:lang="ES">perro</verbiage>


   <note>has no language, so this remains</note>
<verbiage xml:lang="ES">perro</verbiage>

Quote:

> (Using libxml 20507, libxslt 10030 and libexslt 720
> xsltproc was compiled against libxml 20507, libxslt 10030 and libexslt 720
> libxslt 10030 was compiled against libxml 20507
> libexslt 720 was compiled against libxml 20507)

One of these 8 XSLT processors is xsltProc (libxml 20504, libxslt 10027.
libexslt 718)

> BTW I have solved my outer problem with this script:

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

>     <xsl:copy>
>       <xsl:apply-templates



This is incorrect -- see below.

Quote:>     </xsl:copy>
>   </xsl:template>
>  </xsl:stylesheet>

> But it's still not as minimal as I would have liked. One uses it like
this:

In your first message you said "The source has many languages,
and the target only one."

Your solution, when applied with $copy-lang set to "ES" on this source.xml:

<gloss>
  <note lang="CH">
  This has a language different from ES
  and must not be copied!!!
    <subnote xml:lang="ES">perro</subnote>
    <subnote xml:lang="EN">dog</subnote>
  </note>
  <verbiage xml:lang="EN">dog</verbiage>
  <verbiage xml:lang="ES">perro</verbiage>
  <verbiage xml:lang="PT">cao</verbiage>
</gloss>

produces this result:

<?xml version="1.0" encoding="UTF-16"?><gloss>
  <note lang="CH">
  This has a language different from ES
  and must not be copied!!!
    <subnote xml:lang="ES">perro</subnote>

  </note>

  <verbiage xml:lang="ES">perro</verbiage>

</gloss>

The "note" element is in the "CH" language, and the result is in two
languages ("CH" and "ES"), not in one.

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

 
 
 

match if an attribute has a value, or is not available.

Post by Marro » Mon, 07 Jul 2003 07:28:56


Hi Phlip,

I'm not sure if this will apply to the XML documents you are filtering - but
be wary that the xml:lang also applies to descendants of the element on
which it is declared where it is not overridden on those descendants.

For example, the following XML...

<?xml version="1.0"?>
<gloss xml:lang="EN">
  <note>has no language - but is a descendant of one that does</note>
  <verbiage xml:lang="EN">dog</verbiage>
  <verbiage xml:lang="ES">perro</verbiage>
  <verbiage xml:lang="PT">cao</verbiage>
</gloss>

The language of the <note> element is now 'EN' because it desecends from
<gloss> which is defined as 'EN'.  So your current XSLT will copy that
<note> even though it is not 'ES'.  I think maybe a slight tweak to your
XSLT should prevent that from happening...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.veryComputer.com/;>
  <xsl:param name="copy-lang" select="'ES'"/>

    <xsl:copy>
      <xsl:apply-templates


    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

Cheers
Marrow
http://www.veryComputer.com/ - home of Xselerator (XSLT IDE and de*)
http://www.veryComputer.com/



> > or


> Thanks, but (given 'xsltproc oneLang.xslt manyLang.xml'), the second
returns
> only tags with no xml:lang at all, and the first returns no nodes
> whatsoever.

> (Using libxml 20507, libxslt 10030 and libexslt 720
> xsltproc was compiled against libxml 20507, libxslt 10030 and libexslt 720
> libxslt 10030 was compiled against libxml 20507
> libexslt 720 was compiled against libxml 20507)

> BTW I have solved my outer problem with this script:

> <?xml version="1.0"?>
>  <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.veryComputer.com/;>

>     <xsl:copy>
>       <xsl:apply-templates


>     </xsl:copy>
>   </xsl:template>
>  </xsl:stylesheet>

> But it's still not as minimal as I would have liked. One uses it like
this:

>  xsltproc --param copy-lang "'es'" oneLang.xslt manyLang.xml

> --
>   Phlip
>     http://www.veryComputer.com/

 
 
 

1. I am having problem retriving the attributes

I am new with xsl.  I have the sample code below but I am having
problem to get all the attributes value, what is missing here??

  <xsl:template name="DoXml">
    <xsl:for-each select="./*">
      <xsl:call-template name="InnerDoXml"/>
      <br/>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="InnerDoXml">
    <xsl:param name="indent"/>
    <xsl:value-of disable-output-escaping = "yes" select="$indent"/>
    <<xsl:value-of select="name()"/>
    <xsl:if test="namespace-uri(.) != namespace-uri(..)">
      <font color="gray">
        xmlns="<xsl:value-of select="namespace-uri(.)"/>"
      </font>
    </xsl:if>

      <br/>
      <xsl:value-of select="$indent" disable-output-escaping = "yes"/>
      <FONT Color="Orange"><xsl:text disable-output-escaping = "yes">
        &nbsp; &nbsp;
        &nbsp; &nbsp;
      </xsl:text></FONT>
      <xsl:value-of select="name()"/>
      =
    </xsl:for-each>>
    <xsl:choose>
      <xsl:when test="./*">
        <br/>
        <xsl:for-each select="./*">
          <xsl:call-template name="InnerDoXml">
            <xsl:with-param name="indent">
              <xsl:value-of select="$indent"/>
              &nbsp; &nbsp;
            </xsl:with-param>
          </xsl:call-template>
          <br/>
        </xsl:for-each>
        <xsl:value-of disable-output-escaping = "yes"
select="$indent"/>
      </xsl:when>
      <xsl:otherwise>
        <FONT Color="Orange">
          <xsl:value-of select="."/>
        </FONT>
      </xsl:otherwise >
    </xsl:choose>
    </<xsl:value-of select="name()"/>>
  </xsl:template>

2. What is comp.unix.appleiigs ?

3. How do I match the value of an attribute to the value of an element?

4. gadtools.library stringgad help

5. I am not able to retrieve Node's attribute

6. Latex for Win95

7. HOWTO: select using attribute value not in other nodes attr values

8. intersecting surfaces

9. XPath Query - Comparing value of an attribute to value of an element not working

10. Select DISTINCT on attribute value, NOT Node value

11. matching an attribute value

12. Access Nodes by matching attribute value and node Name?

13. XSLT template to match values of several attributes of a xml-tag?