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: Mon, 11 Aug 2008 18:27:46 -0700,    group: microsoft.public.xsl        back       


Pattern problem   
I can't seem to get this pattern to work:

I have stripped down my files for testing:

In a nutshell, what I am trying to do is this:

     <xsl:when test="ancestor::form/@name = '1007'">
      <xsl:value-of select="name[ancestor::form/primary='true']"/>
     </xsl:when>

If the form/@name = '1007', I want to go look at the other form tags to find 
the one that has an attribute primary='true' and use that name for my form 
name.  But I am getting a blank entry.  I was just guessing on this 
statement and not sure how to get it to work:

My xslt file:
*****************************************************
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <xsl:output method="xml" indent="yes"/>
 <xsl:template match="/*">
  <xsl:copy>
   <xsl:apply-templates select="appraisal/data/form/tag | 
appraisal/data/form/section/tag">
    <xsl:sort select="ancestor::form/@primary" order="descending"/>
    <xsl:sort select="ancestor::section/@number" order="ascending" 
data-type="number"/>
   </xsl:apply-templates>
  </xsl:copy>
 </xsl:template>
 <xsl:template match="tag">
  <form>
   <sectionNumber>
    <xsl:value-of select="ancestor::section/@number"/>
   </sectionNumber>
   <primary>
    <xsl:value-of select="ancestor::form/@primary"/>
   </primary>
   <formName>
    <xsl:choose>
     <xsl:when test="ancestor::form/@name = '1007'">
      <xsl:value-of select="name[ancestor::form/primary='true']"/> 
<---------
     </xsl:when>
     <xsl:otherwise>
      <xsl:value-of select="ancestor::form/@name"/>
     </xsl:otherwise>
    </xsl:choose>
   </formName>
   <tagName>
    <xsl:value-of select="@name"/>
   </tagName>
   <flags>
    <xsl:if test="not(@flags)">
     <xsl:attribute name="xsi:nil">true</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@flags"/>
   </flags>
   <format>
    <xsl:if test="not(@format)">
     <xsl:attribute name="xsi:nil">true</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@format"/>
   </format>
   <value>
    <xsl:value-of select="text()"/>
   </value>
  </form>
  <xsl:apply-templates select="addendum[heading | body]"/>
 </xsl:template>
</xsl:stylesheet>
******************************************************

My xml file:
******************************************************
<?xml version="1.0" encoding="utf-8"?>
<Report>
  <appraisal>
    <data>
      <form name="1007" primary="false">
        <section type="subject" number="0">
          <tag name="GR_AGE.1" flags="1" format="4096">4 Yrs.</tag>
        </section>
      </form>
      <form name="reffee" primary="false">
          <tag name="FFHD_NFIP_COMMUNITY_NUMBER.1" flags="0" 
format="0">040040</tag>
      </form>
      <form name="1004_05" primary="true">
        <section type="subject" number="0">
          <tag name="PROP_PHYS_DEFICIENCIES_DESC.1" flags="4" 
format="4096">None apparent </tag>
        </section>
      </form>
    </data>
  </appraisal>
</Report>
********************************************************

My result:
******************************************************
<?xml version="1.0" encoding="utf-8"?>
<Report>
  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <sectionNumber>0</sectionNumber>
    <primary>true</primary>
    <formName>1004_05</formName>
    <tagName>PROP_PHYS_DEFICIENCIES_DESC.1</tagName>
    <flags>4</flags>
    <format>4096</format>
    <value>None apparent </value>
  </form>
  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <sectionNumber></sectionNumber>
    <primary>false</primary>
    <formName>reffee</formName>
    <tagName>FFHD_NFIP_COMMUNITY_NUMBER.1</tagName>
    <flags>0</flags>
    <format>0</format>
    <value>040040</value>
  </form>
  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <sectionNumber>0</sectionNumber>
    <primary>false</primary>
    <formName></formName>                      <-------- Want this to be 
1004_05
    <tagName>GR_AGE.1</tagName>
    <flags>1</flags>
    <format>4096</format>
    <value>4 Yrs.</value>
  </form>
</Report>
*******************************************************

Everything else works fine.

What should that line be?  Do I need to do another match and template?

Thanks,

Tom
date: Mon, 11 Aug 2008 18:27:46 -0700   author:   tshad

Re: Pattern problem   
When you say the name do you mean the formName element, name doesn't make 
sense as the element name is form which you already know?
<xsl:value-of select="ancestor::form[primary='true']/formName"/>

"I was just guessing on this  statement and not sure how to get it to work"
You're not going to get far in XSLT like this, get a good reference such as 
Michael Kay's latest tome from Wrox, XSLT 4th Edition.

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name




"tshad"  wrote in message 
news:eByPhqB$IHA.1036@TK2MSFTNGP03.phx.gbl...
> I can't seem to get this pattern to work:
>
> I have stripped down my files for testing:
>
> In a nutshell, what I am trying to do is this:
>
>     <xsl:when test="ancestor::form/@name = '1007'">
>      <xsl:value-of select="name[ancestor::form/primary='true']"/>
>     </xsl:when>
>
> If the form/@name = '1007', I want to go look at the other form tags to 
> find the one that has an attribute primary='true' and use that name for my 
> form name.  But I am getting a blank entry.  I was just guessing on this 
> statement and not sure how to get it to work:
>
> My xslt file:
> *****************************************************
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <xsl:output method="xml" indent="yes"/>
> <xsl:template match="/*">
>  <xsl:copy>
>   <xsl:apply-templates select="appraisal/data/form/tag | 
> appraisal/data/form/section/tag">
>    <xsl:sort select="ancestor::form/@primary" order="descending"/>
>    <xsl:sort select="ancestor::section/@number" order="ascending" 
> data-type="number"/>
>   </xsl:apply-templates>
>  </xsl:copy>
> </xsl:template>
> <xsl:template match="tag">
>  <form>
>   <sectionNumber>
>    <xsl:value-of select="ancestor::section/@number"/>
>   </sectionNumber>
>   <primary>
>    <xsl:value-of select="ancestor::form/@primary"/>
>   </primary>
>   <formName>
>    <xsl:choose>
>     <xsl:when test="ancestor::form/@name = '1007'">
>      <xsl:value-of select="name[ancestor::form/primary='true']"/> 
> <---------
>     </xsl:when>
>     <xsl:otherwise>
>      <xsl:value-of select="ancestor::form/@name"/>
>     </xsl:otherwise>
>    </xsl:choose>
>   </formName>
>   <tagName>
>    <xsl:value-of select="@name"/>
>   </tagName>
>   <flags>
>    <xsl:if test="not(@flags)">
>     <xsl:attribute name="xsi:nil">true</xsl:attribute>
>    </xsl:if>
>    <xsl:value-of select="@flags"/>
>   </flags>
>   <format>
>    <xsl:if test="not(@format)">
>     <xsl:attribute name="xsi:nil">true</xsl:attribute>
>    </xsl:if>
>    <xsl:value-of select="@format"/>
>   </format>
>   <value>
>    <xsl:value-of select="text()"/>
>   </value>
>  </form>
>  <xsl:apply-templates select="addendum[heading | body]"/>
> </xsl:template>
> </xsl:stylesheet>
> ******************************************************
>
> My xml file:
> ******************************************************
> <?xml version="1.0" encoding="utf-8"?>
> <Report>
>  <appraisal>
>    <data>
>      <form name="1007" primary="false">
>        <section type="subject" number="0">
>          <tag name="GR_AGE.1" flags="1" format="4096">4 Yrs.</tag>
>        </section>
>      </form>
>      <form name="reffee" primary="false">
>          <tag name="FFHD_NFIP_COMMUNITY_NUMBER.1" flags="0" 
> format="0">040040</tag>
>      </form>
>      <form name="1004_05" primary="true">
>        <section type="subject" number="0">
>          <tag name="PROP_PHYS_DEFICIENCIES_DESC.1" flags="4" 
> format="4096">None apparent </tag>
>        </section>
>      </form>
>    </data>
>  </appraisal>
> </Report>
> ********************************************************
>
> My result:
> ******************************************************
> <?xml version="1.0" encoding="utf-8"?>
> <Report>
>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>    <sectionNumber>0</sectionNumber>
>    <primary>true</primary>
>    <formName>1004_05</formName>
>    <tagName>PROP_PHYS_DEFICIENCIES_DESC.1</tagName>
>    <flags>4</flags>
>    <format>4096</format>
>    <value>None apparent </value>
>  </form>
>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>    <sectionNumber></sectionNumber>
>    <primary>false</primary>
>    <formName>reffee</formName>
>    <tagName>FFHD_NFIP_COMMUNITY_NUMBER.1</tagName>
>    <flags>0</flags>
>    <format>0</format>
>    <value>040040</value>
>  </form>
>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>    <sectionNumber>0</sectionNumber>
>    <primary>false</primary>
>    <formName></formName>                      <-------- Want this to be 
> 1004_05
>    <tagName>GR_AGE.1</tagName>
>    <flags>1</flags>
>    <format>4096</format>
>    <value>4 Yrs.</value>
>  </form>
> </Report>
> *******************************************************
>
> Everything else works fine.
>
> What should that line be?  Do I need to do another match and template?
>
> Thanks,
>
> Tom
>
date: Tue, 12 Aug 2008 07:26:14 +0100   author:   Joe Fawcett am

Re: Pattern problem   
"Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message 
news:%23%23DITRE$IHA.3472@TK2MSFTNGP05.phx.gbl...
> When you say the name do you mean the formName element, name doesn't make 
> sense as the element name is form which you already know?
> <xsl:value-of select="ancestor::form[primary='true']/formName"/>

Actually, the result I showed that I was looking for, was incorrect.  Sorry.

What I wanted the last set to look like was:

  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <sectionNumber>0</sectionNumber>
    <primary>false</primary>
    <formName>1004_05</formName>                      <-------- Want it to 
look like this.
    <tagName>GR_AGE.1</tagName>
    <flags>1</flags>
    <format>4096</format>
    <value>4 Yrs.</value>
  </form>

and I realize oneof my mistakes was that I don't want "name", but "@name".

Would I change you line to:

<xsl:value-of select="ancestor::form[primary='true']/@name"/>

>
> "I was just guessing on this  statement and not sure how to get it to 
> work"
> You're not going to get far in XSLT like this, get a good reference such 
> as Michael Kay's latest tome from Wrox, XSLT 4th Edition.

I will.

I only have the O'Reilly book (Learning XSLT).

Thanks,

Tom
>
> -- 
>
> Joe Fawcett (MVP - XML)
> http://joe.fawcett.name
>
>
>
>
> "tshad"  wrote in message 
> news:eByPhqB$IHA.1036@TK2MSFTNGP03.phx.gbl...
>> I can't seem to get this pattern to work:
>>
>> I have stripped down my files for testing:
>>
>> In a nutshell, what I am trying to do is this:
>>
>>     <xsl:when test="ancestor::form/@name = '1007'">
>>      <xsl:value-of select="name[ancestor::form/primary='true']"/>
>>     </xsl:when>
>>
>> If the form/@name = '1007', I want to go look at the other form tags to 
>> find the one that has an attribute primary='true' and use that name for 
>> my form name.  But I am getting a blank entry.  I was just guessing on 
>> this statement and not sure how to get it to work:
>>
>> My xslt file:
>> *****************************************************
>> <xsl:stylesheet version="1.0"
>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>> <xsl:output method="xml" indent="yes"/>
>> <xsl:template match="/*">
>>  <xsl:copy>
>>   <xsl:apply-templates select="appraisal/data/form/tag | 
>> appraisal/data/form/section/tag">
>>    <xsl:sort select="ancestor::form/@primary" order="descending"/>
>>    <xsl:sort select="ancestor::section/@number" order="ascending" 
>> data-type="number"/>
>>   </xsl:apply-templates>
>>  </xsl:copy>
>> </xsl:template>
>> <xsl:template match="tag">
>>  <form>
>>   <sectionNumber>
>>    <xsl:value-of select="ancestor::section/@number"/>
>>   </sectionNumber>
>>   <primary>
>>    <xsl:value-of select="ancestor::form/@primary"/>
>>   </primary>
>>   <formName>
>>    <xsl:choose>
>>     <xsl:when test="ancestor::form/@name = '1007'">
>>      <xsl:value-of select="name[ancestor::form/primary='true']"/> 
>> <---------
>>     </xsl:when>
>>     <xsl:otherwise>
>>      <xsl:value-of select="ancestor::form/@name"/>
>>     </xsl:otherwise>
>>    </xsl:choose>
>>   </formName>
>>   <tagName>
>>    <xsl:value-of select="@name"/>
>>   </tagName>
>>   <flags>
>>    <xsl:if test="not(@flags)">
>>     <xsl:attribute name="xsi:nil">true</xsl:attribute>
>>    </xsl:if>
>>    <xsl:value-of select="@flags"/>
>>   </flags>
>>   <format>
>>    <xsl:if test="not(@format)">
>>     <xsl:attribute name="xsi:nil">true</xsl:attribute>
>>    </xsl:if>
>>    <xsl:value-of select="@format"/>
>>   </format>
>>   <value>
>>    <xsl:value-of select="text()"/>
>>   </value>
>>  </form>
>>  <xsl:apply-templates select="addendum[heading | body]"/>
>> </xsl:template>
>> </xsl:stylesheet>
>> ******************************************************
>>
>> My xml file:
>> ******************************************************
>> <?xml version="1.0" encoding="utf-8"?>
>> <Report>
>>  <appraisal>
>>    <data>
>>      <form name="1007" primary="false">
>>        <section type="subject" number="0">
>>          <tag name="GR_AGE.1" flags="1" format="4096">4 Yrs.</tag>
>>        </section>
>>      </form>
>>      <form name="reffee" primary="false">
>>          <tag name="FFHD_NFIP_COMMUNITY_NUMBER.1" flags="0" 
>> format="0">040040</tag>
>>      </form>
>>      <form name="1004_05" primary="true">
>>        <section type="subject" number="0">
>>          <tag name="PROP_PHYS_DEFICIENCIES_DESC.1" flags="4" 
>> format="4096">None apparent </tag>
>>        </section>
>>      </form>
>>    </data>
>>  </appraisal>
>> </Report>
>> ********************************************************
>>
>> My result:
>> ******************************************************
>> <?xml version="1.0" encoding="utf-8"?>
>> <Report>
>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>    <sectionNumber>0</sectionNumber>
>>    <primary>true</primary>
>>    <formName>1004_05</formName>
>>    <tagName>PROP_PHYS_DEFICIENCIES_DESC.1</tagName>
>>    <flags>4</flags>
>>    <format>4096</format>
>>    <value>None apparent </value>
>>  </form>
>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>    <sectionNumber></sectionNumber>
>>    <primary>false</primary>
>>    <formName>reffee</formName>
>>    <tagName>FFHD_NFIP_COMMUNITY_NUMBER.1</tagName>
>>    <flags>0</flags>
>>    <format>0</format>
>>    <value>040040</value>
>>  </form>
>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>    <sectionNumber>0</sectionNumber>
>>    <primary>false</primary>
>>    <formName></formName>                      <-------- Want this to be 
>> 1004_05
>>    <tagName>GR_AGE.1</tagName>
>>    <flags>1</flags>
>>    <format>4096</format>
>>    <value>4 Yrs.</value>
>>  </form>
>> </Report>
>> *******************************************************
>>
>> Everything else works fine.
>>
>> What should that line be?  Do I need to do another match and template?
>>
>> Thanks,
>>
>> Tom
>>
date: Tue, 12 Aug 2008 07:43:22 -0700   author:   tshad

Re: Pattern problem   
"tshad"  wrote in message 
news:eFEpEnI$IHA.3696@TK2MSFTNGP06.phx.gbl...
>
> "Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message 
> news:%23%23DITRE$IHA.3472@TK2MSFTNGP05.phx.gbl...
>> When you say the name do you mean the formName element, name doesn't make 
>> sense as the element name is form which you already know?
>> <xsl:value-of select="ancestor::form[primary='true']/formName"/>
>
> Actually, the result I showed that I was looking for, was incorrect. 
> Sorry.
>
> What I wanted the last set to look like was:
>
>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>    <sectionNumber>0</sectionNumber>
>    <primary>false</primary>
>    <formName>1004_05</formName>                      <-------- Want it to 
> look like this.
>    <tagName>GR_AGE.1</tagName>
>    <flags>1</flags>
>    <format>4096</format>
>    <value>4 Yrs.</value>
>  </form>
>
> and I realize oneof my mistakes was that I don't want "name", but "@name".
>
> Would I change you line to:
>
> <xsl:value-of select="ancestor::form[primary='true']/@name"/>
>
>>

That doesn't seem to work either.

I changed the "choose" section of the <formName> part to:

   <formName>
    <xsl:choose>
     <xsl:when test="ancestor::form/@name = '1007'">
      <xsl:value-of select="ancestor::form[primary='true']/@name"/>
     </xsl:when>
     <xsl:otherwise>
      <xsl:value-of select="ancestor::form/@name"/>
     </xsl:otherwise>
    </xsl:choose>
   </formName>

but I am still getting

    <formName></formName>

Tom
>> "I was just guessing on this  statement and not sure how to get it to 
>> work"
>> You're not going to get far in XSLT like this, get a good reference such 
>> as Michael Kay's latest tome from Wrox, XSLT 4th Edition.
>
> I will.
>
> I only have the O'Reilly book (Learning XSLT).
>
> Thanks,
>
> Tom
>>
>> -- 
>>
>> Joe Fawcett (MVP - XML)
>> http://joe.fawcett.name
>>
>>
>>
>>
>> "tshad"  wrote in message 
>> news:eByPhqB$IHA.1036@TK2MSFTNGP03.phx.gbl...
>>> I can't seem to get this pattern to work:
>>>
>>> I have stripped down my files for testing:
>>>
>>> In a nutshell, what I am trying to do is this:
>>>
>>>     <xsl:when test="ancestor::form/@name = '1007'">
>>>      <xsl:value-of select="name[ancestor::form/primary='true']"/>
>>>     </xsl:when>
>>>
>>> If the form/@name = '1007', I want to go look at the other form tags to 
>>> find the one that has an attribute primary='true' and use that name for 
>>> my form name.  But I am getting a blank entry.  I was just guessing on 
>>> this statement and not sure how to get it to work:
>>>
>>> My xslt file:
>>> *****************************************************
>>> <xsl:stylesheet version="1.0"
>>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>>                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>> <xsl:output method="xml" indent="yes"/>
>>> <xsl:template match="/*">
>>>  <xsl:copy>
>>>   <xsl:apply-templates select="appraisal/data/form/tag | 
>>> appraisal/data/form/section/tag">
>>>    <xsl:sort select="ancestor::form/@primary" order="descending"/>
>>>    <xsl:sort select="ancestor::section/@number" order="ascending" 
>>> data-type="number"/>
>>>   </xsl:apply-templates>
>>>  </xsl:copy>
>>> </xsl:template>
>>> <xsl:template match="tag">
>>>  <form>
>>>   <sectionNumber>
>>>    <xsl:value-of select="ancestor::section/@number"/>
>>>   </sectionNumber>
>>>   <primary>
>>>    <xsl:value-of select="ancestor::form/@primary"/>
>>>   </primary>
>>>   <formName>
>>>    <xsl:choose>
>>>     <xsl:when test="ancestor::form/@name = '1007'">
>>>      <xsl:value-of select="name[ancestor::form/primary='true']"/> 
>>> <---------
>>>     </xsl:when>
>>>     <xsl:otherwise>
>>>      <xsl:value-of select="ancestor::form/@name"/>
>>>     </xsl:otherwise>
>>>    </xsl:choose>
>>>   </formName>
>>>   <tagName>
>>>    <xsl:value-of select="@name"/>
>>>   </tagName>
>>>   <flags>
>>>    <xsl:if test="not(@flags)">
>>>     <xsl:attribute name="xsi:nil">true</xsl:attribute>
>>>    </xsl:if>
>>>    <xsl:value-of select="@flags"/>
>>>   </flags>
>>>   <format>
>>>    <xsl:if test="not(@format)">
>>>     <xsl:attribute name="xsi:nil">true</xsl:attribute>
>>>    </xsl:if>
>>>    <xsl:value-of select="@format"/>
>>>   </format>
>>>   <value>
>>>    <xsl:value-of select="text()"/>
>>>   </value>
>>>  </form>
>>>  <xsl:apply-templates select="addendum[heading | body]"/>
>>> </xsl:template>
>>> </xsl:stylesheet>
>>> ******************************************************
>>>
>>> My xml file:
>>> ******************************************************
>>> <?xml version="1.0" encoding="utf-8"?>
>>> <Report>
>>>  <appraisal>
>>>    <data>
>>>      <form name="1007" primary="false">
>>>        <section type="subject" number="0">
>>>          <tag name="GR_AGE.1" flags="1" format="4096">4 Yrs.</tag>
>>>        </section>
>>>      </form>
>>>      <form name="reffee" primary="false">
>>>          <tag name="FFHD_NFIP_COMMUNITY_NUMBER.1" flags="0" 
>>> format="0">040040</tag>
>>>      </form>
>>>      <form name="1004_05" primary="true">
>>>        <section type="subject" number="0">
>>>          <tag name="PROP_PHYS_DEFICIENCIES_DESC.1" flags="4" 
>>> format="4096">None apparent </tag>
>>>        </section>
>>>      </form>
>>>    </data>
>>>  </appraisal>
>>> </Report>
>>> ********************************************************
>>>
>>> My result:
>>> ******************************************************
>>> <?xml version="1.0" encoding="utf-8"?>
>>> <Report>
>>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>    <sectionNumber>0</sectionNumber>
>>>    <primary>true</primary>
>>>    <formName>1004_05</formName>
>>>    <tagName>PROP_PHYS_DEFICIENCIES_DESC.1</tagName>
>>>    <flags>4</flags>
>>>    <format>4096</format>
>>>    <value>None apparent </value>
>>>  </form>
>>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>    <sectionNumber></sectionNumber>
>>>    <primary>false</primary>
>>>    <formName>reffee</formName>
>>>    <tagName>FFHD_NFIP_COMMUNITY_NUMBER.1</tagName>
>>>    <flags>0</flags>
>>>    <format>0</format>
>>>    <value>040040</value>
>>>  </form>
>>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>    <sectionNumber>0</sectionNumber>
>>>    <primary>false</primary>
>>>    <formName></formName>                      <-------- Want this to be 
>>> 1004_05
>>>    <tagName>GR_AGE.1</tagName>
>>>    <flags>1</flags>
>>>    <format>4096</format>
>>>    <value>4 Yrs.</value>
>>>  </form>
>>> </Report>
>>> *******************************************************
>>>
>>> Everything else works fine.
>>>
>>> What should that line be?  Do I need to do another match and template?
>>>
>>> Thanks,
>>>
>>> Tom
>>>
>
>
date: Tue, 12 Aug 2008 09:13:56 -0700   author:   tshad

Re: Pattern problem   
"tshad"  wrote in message 
news:eFEpEnI$IHA.3696@TK2MSFTNGP06.phx.gbl...
>
> "Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message 
> news:%23%23DITRE$IHA.3472@TK2MSFTNGP05.phx.gbl...
>> When you say the name do you mean the formName element, name doesn't make 
>> sense as the element name is form which you already know?
>> <xsl:value-of select="ancestor::form[primary='true']/formName"/>
>
> Actually, the result I showed that I was looking for, was incorrect. 
> Sorry.
>
> What I wanted the last set to look like was:
>
>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>    <sectionNumber>0</sectionNumber>
>    <primary>false</primary>
>    <formName>1004_05</formName>                      <-------- Want it to 
> look like this.
>    <tagName>GR_AGE.1</tagName>
>    <flags>1</flags>
>    <format>4096</format>
>    <value>4 Yrs.</value>
>  </form>
>
> and I realize oneof my mistakes was that I don't want "name", but "@name".
>
> Would I change you line to:
>
> <xsl:value-of select="ancestor::form[primary='true']/@name"/>
>

That looks right.

>>
>> "I was just guessing on this  statement and not sure how to get it to 
>> work"
>> You're not going to get far in XSLT like this, get a good reference such 
>> as Michael Kay's latest tome from Wrox, XSLT 4th Edition.
>
> I will.
>
> I only have the O'Reilly book (Learning XSLT).

That should be fine, just take a look at predicates in XPath.

>
> Thanks,
>
> Tom

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name
date: Tue, 12 Aug 2008 17:16:32 +0100   author:   Joe Fawcett am

Re: Pattern problem   
"tshad"  wrote in message 
news:%23575tZJ$IHA.5192@TK2MSFTNGP04.phx.gbl...
>
> "tshad"  wrote in message 
> news:eFEpEnI$IHA.3696@TK2MSFTNGP06.phx.gbl...
>>
>> "Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message 
>> news:%23%23DITRE$IHA.3472@TK2MSFTNGP05.phx.gbl...
>>> When you say the name do you mean the formName element, name doesn't 
>>> make sense as the element name is form which you already know?
>>> <xsl:value-of select="ancestor::form[primary='true']/formName"/>
>>
>> Actually, the result I showed that I was looking for, was incorrect. 
>> Sorry.
>>
>> What I wanted the last set to look like was:
>>
>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>    <sectionNumber>0</sectionNumber>
>>    <primary>false</primary>
>>    <formName>1004_05</formName>                      <-------- Want it to 
>> look like this.
>>    <tagName>GR_AGE.1</tagName>
>>    <flags>1</flags>
>>    <format>4096</format>
>>    <value>4 Yrs.</value>
>>  </form>
>>
>> and I realize oneof my mistakes was that I don't want "name", but 
>> "@name".
>>
>> Would I change you line to:
>>
>> <xsl:value-of select="ancestor::form[primary='true']/@name"/>

I also tried:

<xsl:value-of select="preceding::form[primary='true']/@name"/>

and

<xsl:value-of select="preceding-sibling::form[primary='true']/@name"/>

and the VS 2005 QuickWatch shows the result as {Dimension:[0]}.  Not sure 
what that means but I assume it means it found nothing.

Tom

>>
>>>
>
> That doesn't seem to work either.
>
> I changed the "choose" section of the <formName> part to:
>
>   <formName>
>    <xsl:choose>
>     <xsl:when test="ancestor::form/@name = '1007'">
>      <xsl:value-of select="ancestor::form[primary='true']/@name"/>
>     </xsl:when>
>     <xsl:otherwise>
>      <xsl:value-of select="ancestor::form/@name"/>
>     </xsl:otherwise>
>    </xsl:choose>
>   </formName>
>
> but I am still getting
>
>    <formName></formName>
>
> Tom
>>> "I was just guessing on this  statement and not sure how to get it to 
>>> work"
>>> You're not going to get far in XSLT like this, get a good reference such 
>>> as Michael Kay's latest tome from Wrox, XSLT 4th Edition.
>>
>> I will.
>>
>> I only have the O'Reilly book (Learning XSLT).
>>
>> Thanks,
>>
>> Tom
>>>
>>> -- 
>>>
>>> Joe Fawcett (MVP - XML)
>>> http://joe.fawcett.name
>>>
>>>
>>>
>>>
>>> "tshad"  wrote in message 
>>> news:eByPhqB$IHA.1036@TK2MSFTNGP03.phx.gbl...
>>>> I can't seem to get this pattern to work:
>>>>
>>>> I have stripped down my files for testing:
>>>>
>>>> In a nutshell, what I am trying to do is this:
>>>>
>>>>     <xsl:when test="ancestor::form/@name = '1007'">
>>>>      <xsl:value-of select="name[ancestor::form/primary='true']"/>
>>>>     </xsl:when>
>>>>
>>>> If the form/@name = '1007', I want to go look at the other form tags to 
>>>> find the one that has an attribute primary='true' and use that name for 
>>>> my form name.  But I am getting a blank entry.  I was just guessing on 
>>>> this statement and not sure how to get it to work:
>>>>
>>>> My xslt file:
>>>> *****************************************************
>>>> <xsl:stylesheet version="1.0"
>>>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>>>                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>> <xsl:output method="xml" indent="yes"/>
>>>> <xsl:template match="/*">
>>>>  <xsl:copy>
>>>>   <xsl:apply-templates select="appraisal/data/form/tag | 
>>>> appraisal/data/form/section/tag">
>>>>    <xsl:sort select="ancestor::form/@primary" order="descending"/>
>>>>    <xsl:sort select="ancestor::section/@number" order="ascending" 
>>>> data-type="number"/>
>>>>   </xsl:apply-templates>
>>>>  </xsl:copy>
>>>> </xsl:template>
>>>> <xsl:template match="tag">
>>>>  <form>
>>>>   <sectionNumber>
>>>>    <xsl:value-of select="ancestor::section/@number"/>
>>>>   </sectionNumber>
>>>>   <primary>
>>>>    <xsl:value-of select="ancestor::form/@primary"/>
>>>>   </primary>
>>>>   <formName>
>>>>    <xsl:choose>
>>>>     <xsl:when test="ancestor::form/@name = '1007'">
>>>>      <xsl:value-of select="name[ancestor::form/primary='true']"/> 
>>>> <---------
>>>>     </xsl:when>
>>>>     <xsl:otherwise>
>>>>      <xsl:value-of select="ancestor::form/@name"/>
>>>>     </xsl:otherwise>
>>>>    </xsl:choose>
>>>>   </formName>
>>>>   <tagName>
>>>>    <xsl:value-of select="@name"/>
>>>>   </tagName>
>>>>   <flags>
>>>>    <xsl:if test="not(@flags)">
>>>>     <xsl:attribute name="xsi:nil">true</xsl:attribute>
>>>>    </xsl:if>
>>>>    <xsl:value-of select="@flags"/>
>>>>   </flags>
>>>>   <format>
>>>>    <xsl:if test="not(@format)">
>>>>     <xsl:attribute name="xsi:nil">true</xsl:attribute>
>>>>    </xsl:if>
>>>>    <xsl:value-of select="@format"/>
>>>>   </format>
>>>>   <value>
>>>>    <xsl:value-of select="text()"/>
>>>>   </value>
>>>>  </form>
>>>>  <xsl:apply-templates select="addendum[heading | body]"/>
>>>> </xsl:template>
>>>> </xsl:stylesheet>
>>>> ******************************************************
>>>>
>>>> My xml file:
>>>> ******************************************************
>>>> <?xml version="1.0" encoding="utf-8"?>
>>>> <Report>
>>>>  <appraisal>
>>>>    <data>
>>>>      <form name="1007" primary="false">
>>>>        <section type="subject" number="0">
>>>>          <tag name="GR_AGE.1" flags="1" format="4096">4 Yrs.</tag>
>>>>        </section>
>>>>      </form>
>>>>      <form name="reffee" primary="false">
>>>>          <tag name="FFHD_NFIP_COMMUNITY_NUMBER.1" flags="0" 
>>>> format="0">040040</tag>
>>>>      </form>
>>>>      <form name="1004_05" primary="true">
>>>>        <section type="subject" number="0">
>>>>          <tag name="PROP_PHYS_DEFICIENCIES_DESC.1" flags="4" 
>>>> format="4096">None apparent </tag>
>>>>        </section>
>>>>      </form>
>>>>    </data>
>>>>  </appraisal>
>>>> </Report>
>>>> ********************************************************
>>>>
>>>> My result:
>>>> ******************************************************
>>>> <?xml version="1.0" encoding="utf-8"?>
>>>> <Report>
>>>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>>    <sectionNumber>0</sectionNumber>
>>>>    <primary>true</primary>
>>>>    <formName>1004_05</formName>
>>>>    <tagName>PROP_PHYS_DEFICIENCIES_DESC.1</tagName>
>>>>    <flags>4</flags>
>>>>    <format>4096</format>
>>>>    <value>None apparent </value>
>>>>  </form>
>>>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>>    <sectionNumber></sectionNumber>
>>>>    <primary>false</primary>
>>>>    <formName>reffee</formName>
>>>>    <tagName>FFHD_NFIP_COMMUNITY_NUMBER.1</tagName>
>>>>    <flags>0</flags>
>>>>    <format>0</format>
>>>>    <value>040040</value>
>>>>  </form>
>>>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>>    <sectionNumber>0</sectionNumber>
>>>>    <primary>false</primary>
>>>>    <formName></formName>                      <-------- Want this to be 
>>>> 1004_05
>>>>    <tagName>GR_AGE.1</tagName>
>>>>    <flags>1</flags>
>>>>    <format>4096</format>
>>>>    <value>4 Yrs.</value>
>>>>  </form>
>>>> </Report>
>>>> *******************************************************
>>>>
>>>> Everything else works fine.
>>>>
>>>> What should that line be?  Do I need to do another match and template?
>>>>
>>>> Thanks,
>>>>
>>>> Tom
>>>>
>>
>>
>
>
date: Tue, 12 Aug 2008 15:49:24 -0700   author:   tshad

Re: Pattern problem   
"tshad"  wrote in message 
news:u$Rvt2M$IHA.1180@TK2MSFTNGP04.phx.gbl...
>
> "tshad"  wrote in message 
> news:%23575tZJ$IHA.5192@TK2MSFTNGP04.phx.gbl...
>>
>> "tshad"  wrote in message 
>> news:eFEpEnI$IHA.3696@TK2MSFTNGP06.phx.gbl...
>>>
>>> "Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message 
>>> news:%23%23DITRE$IHA.3472@TK2MSFTNGP05.phx.gbl...
>>>> When you say the name do you mean the formName element, name doesn't 
>>>> make sense as the element name is form which you already know?
>>>> <xsl:value-of select="ancestor::form[primary='true']/formName"/>
>>>
>>> Actually, the result I showed that I was looking for, was incorrect. 
>>> Sorry.
>>>
>>> What I wanted the last set to look like was:
>>>
>>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>    <sectionNumber>0</sectionNumber>
>>>    <primary>false</primary>
>>>    <formName>1004_05</formName>                      <-------- Want it 
>>> to look like this.
>>>    <tagName>GR_AGE.1</tagName>
>>>    <flags>1</flags>
>>>    <format>4096</format>
>>>    <value>4 Yrs.</value>
>>>  </form>
>>>
>>> and I realize oneof my mistakes was that I don't want "name", but 
>>> "@name".
>>>
>>> Would I change you line to:
>>>
>>> <xsl:value-of select="ancestor::form[primary='true']/@name"/>
>
> I also tried:
>
> <xsl:value-of select="preceding::form[primary='true']/@name"/>
>
> and
>
> <xsl:value-of select="preceding-sibling::form[primary='true']/@name"/>
>
> and the VS 2005 QuickWatch shows the result as {Dimension:[0]}.  Not sure 
> what that means but I assume it means it found nothing.

ancestor::form/@name gives me 1007, as it should.  But I need to look at all 
the forms on the same level and get the one that has @primary = 'true' and 
use the @name of that form.

Is this the wrong way to get that?

Seems pretty straight forward.

I assume the pattern in:

<xsl:value-of select="ancestor::form[@primary='true']/@name"/>

says to look for all the ancestor "form" tags and look at the one that one. 
I did notice that I had primary set in my program without the "@".  But even 
after changing it to the above is not working.

Thanks,

Tom
>
> Tom
>
>>>
>>>>
>>
>> That doesn't seem to work either.
>>
>> I changed the "choose" section of the <formName> part to:
>>
>>   <formName>
>>    <xsl:choose>
>>     <xsl:when test="ancestor::form/@name = '1007'">
>>      <xsl:value-of select="ancestor::form[primary='true']/@name"/>
>>     </xsl:when>
>>     <xsl:otherwise>
>>      <xsl:value-of select="ancestor::form/@name"/>
>>     </xsl:otherwise>
>>    </xsl:choose>
>>   </formName>
>>
>> but I am still getting
>>
>>    <formName></formName>
>>
>> Tom
>>>> "I was just guessing on this  statement and not sure how to get it to 
>>>> work"
>>>> You're not going to get far in XSLT like this, get a good reference 
>>>> such as Michael Kay's latest tome from Wrox, XSLT 4th Edition.
>>>
>>> I will.
>>>
>>> I only have the O'Reilly book (Learning XSLT).
>>>
>>> Thanks,
>>>
>>> Tom
>>>>
>>>> -- 
>>>>
>>>> Joe Fawcett (MVP - XML)
>>>> http://joe.fawcett.name
>>>>
>>>>
>>>>
>>>>
>>>> "tshad"  wrote in message 
>>>> news:eByPhqB$IHA.1036@TK2MSFTNGP03.phx.gbl...
>>>>> I can't seem to get this pattern to work:
>>>>>
>>>>> I have stripped down my files for testing:
>>>>>
>>>>> In a nutshell, what I am trying to do is this:
>>>>>
>>>>>     <xsl:when test="ancestor::form/@name = '1007'">
>>>>>      <xsl:value-of select="name[ancestor::form/primary='true']"/>
>>>>>     </xsl:when>
>>>>>
>>>>> If the form/@name = '1007', I want to go look at the other form tags 
>>>>> to find the one that has an attribute primary='true' and use that name 
>>>>> for my form name.  But I am getting a blank entry.  I was just 
>>>>> guessing on this statement and not sure how to get it to work:
>>>>>
>>>>> My xslt file:
>>>>> *****************************************************
>>>>> <xsl:stylesheet version="1.0"
>>>>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>>>>                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>>> <xsl:output method="xml" indent="yes"/>
>>>>> <xsl:template match="/*">
>>>>>  <xsl:copy>
>>>>>   <xsl:apply-templates select="appraisal/data/form/tag | 
>>>>> appraisal/data/form/section/tag">
>>>>>    <xsl:sort select="ancestor::form/@primary" order="descending"/>
>>>>>    <xsl:sort select="ancestor::section/@number" order="ascending" 
>>>>> data-type="number"/>
>>>>>   </xsl:apply-templates>
>>>>>  </xsl:copy>
>>>>> </xsl:template>
>>>>> <xsl:template match="tag">
>>>>>  <form>
>>>>>   <sectionNumber>
>>>>>    <xsl:value-of select="ancestor::section/@number"/>
>>>>>   </sectionNumber>
>>>>>   <primary>
>>>>>    <xsl:value-of select="ancestor::form/@primary"/>
>>>>>   </primary>
>>>>>   <formName>
>>>>>    <xsl:choose>
>>>>>     <xsl:when test="ancestor::form/@name = '1007'">
>>>>>      <xsl:value-of select="name[ancestor::form/primary='true']"/> 
>>>>> <---------
>>>>>     </xsl:when>
>>>>>     <xsl:otherwise>
>>>>>      <xsl:value-of select="ancestor::form/@name"/>
>>>>>     </xsl:otherwise>
>>>>>    </xsl:choose>
>>>>>   </formName>
>>>>>   <tagName>
>>>>>    <xsl:value-of select="@name"/>
>>>>>   </tagName>
>>>>>   <flags>
>>>>>    <xsl:if test="not(@flags)">
>>>>>     <xsl:attribute name="xsi:nil">true</xsl:attribute>
>>>>>    </xsl:if>
>>>>>    <xsl:value-of select="@flags"/>
>>>>>   </flags>
>>>>>   <format>
>>>>>    <xsl:if test="not(@format)">
>>>>>     <xsl:attribute name="xsi:nil">true</xsl:attribute>
>>>>>    </xsl:if>
>>>>>    <xsl:value-of select="@format"/>
>>>>>   </format>
>>>>>   <value>
>>>>>    <xsl:value-of select="text()"/>
>>>>>   </value>
>>>>>  </form>
>>>>>  <xsl:apply-templates select="addendum[heading | body]"/>
>>>>> </xsl:template>
>>>>> </xsl:stylesheet>
>>>>> ******************************************************
>>>>>
>>>>> My xml file:
>>>>> ******************************************************
>>>>> <?xml version="1.0" encoding="utf-8"?>
>>>>> <Report>
>>>>>  <appraisal>
>>>>>    <data>
>>>>>      <form name="1007" primary="false">
>>>>>        <section type="subject" number="0">
>>>>>          <tag name="GR_AGE.1" flags="1" format="4096">4 Yrs.</tag>
>>>>>        </section>
>>>>>      </form>
>>>>>      <form name="reffee" primary="false">
>>>>>          <tag name="FFHD_NFIP_COMMUNITY_NUMBER.1" flags="0" 
>>>>> format="0">040040</tag>
>>>>>      </form>
>>>>>      <form name="1004_05" primary="true">
>>>>>        <section type="subject" number="0">
>>>>>          <tag name="PROP_PHYS_DEFICIENCIES_DESC.1" flags="4" 
>>>>> format="4096">None apparent </tag>
>>>>>        </section>
>>>>>      </form>
>>>>>    </data>
>>>>>  </appraisal>
>>>>> </Report>
>>>>> ********************************************************
>>>>>
>>>>> My result:
>>>>> ******************************************************
>>>>> <?xml version="1.0" encoding="utf-8"?>
>>>>> <Report>
>>>>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>>>    <sectionNumber>0</sectionNumber>
>>>>>    <primary>true</primary>
>>>>>    <formName>1004_05</formName>
>>>>>    <tagName>PROP_PHYS_DEFICIENCIES_DESC.1</tagName>
>>>>>    <flags>4</flags>
>>>>>    <format>4096</format>
>>>>>    <value>None apparent </value>
>>>>>  </form>
>>>>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>>>    <sectionNumber></sectionNumber>
>>>>>    <primary>false</primary>
>>>>>    <formName>reffee</formName>
>>>>>    <tagName>FFHD_NFIP_COMMUNITY_NUMBER.1</tagName>
>>>>>    <flags>0</flags>
>>>>>    <format>0</format>
>>>>>    <value>040040</value>
>>>>>  </form>
>>>>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>>>    <sectionNumber>0</sectionNumber>
>>>>>    <primary>false</primary>
>>>>>    <formName></formName>                      <-------- Want this to 
>>>>> be 1004_05
>>>>>    <tagName>GR_AGE.1</tagName>
>>>>>    <flags>1</flags>
>>>>>    <format>4096</format>
>>>>>    <value>4 Yrs.</value>
>>>>>  </form>
>>>>> </Report>
>>>>> *******************************************************
>>>>>
>>>>> Everything else works fine.
>>>>>
>>>>> What should that line be?  Do I need to do another match and template?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Tom
>>>>>
>>>
>>>
>>
>>
>
>
date: Tue, 12 Aug 2008 16:02:29 -0700   author:   tshad

Re: Pattern problem   
I'm lost. Can you show a definitive example of the XML?

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name

"tshad"  wrote in message 
news:uOPHB#M$IHA.4616@TK2MSFTNGP06.phx.gbl...
>
> "tshad"  wrote in message 
> news:u$Rvt2M$IHA.1180@TK2MSFTNGP04.phx.gbl...
>>
>> "tshad"  wrote in message 
>> news:%23575tZJ$IHA.5192@TK2MSFTNGP04.phx.gbl...
>>>
>>> "tshad"  wrote in message 
>>> news:eFEpEnI$IHA.3696@TK2MSFTNGP06.phx.gbl...
>>>>
>>>> "Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message 
>>>> news:%23%23DITRE$IHA.3472@TK2MSFTNGP05.phx.gbl...
>>>>> When you say the name do you mean the formName element, name doesn't 
>>>>> make sense as the element name is form which you already know?
>>>>> <xsl:value-of select="ancestor::form[primary='true']/formName"/>
>>>>
>>>> Actually, the result I showed that I was looking for, was incorrect. 
>>>> Sorry.
>>>>
>>>> What I wanted the last set to look like was:
>>>>
>>>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>>    <sectionNumber>0</sectionNumber>
>>>>    <primary>false</primary>
>>>>    <formName>1004_05</formName>                      <-------- Want it 
>>>> to look like this.
>>>>    <tagName>GR_AGE.1</tagName>
>>>>    <flags>1</flags>
>>>>    <format>4096</format>
>>>>    <value>4 Yrs.</value>
>>>>  </form>
>>>>
>>>> and I realize oneof my mistakes was that I don't want "name", but 
>>>> "@name".
>>>>
>>>> Would I change you line to:
>>>>
>>>> <xsl:value-of select="ancestor::form[primary='true']/@name"/>
>>
>> I also tried:
>>
>> <xsl:value-of select="preceding::form[primary='true']/@name"/>
>>
>> and
>>
>> <xsl:value-of select="preceding-sibling::form[primary='true']/@name"/>
>>
>> and the VS 2005 QuickWatch shows the result as {Dimension:[0]}.  Not sure 
>> what that means but I assume it means it found nothing.
>
> ancestor::form/@name gives me 1007, as it should.  But I need to look at 
> all the forms on the same level and get the one that has @primary = 'true' 
> and use the @name of that form.
>
> Is this the wrong way to get that?
>
> Seems pretty straight forward.
>
> I assume the pattern in:
>
> <xsl:value-of select="ancestor::form[@primary='true']/@name"/>
>
> says to look for all the ancestor "form" tags and look at the one that 
> one. I did notice that I had primary set in my program without the "@". 
> But even after changing it to the above is not working.
>
> Thanks,
>
> Tom
>>
>> Tom
>>
>>>>
>>>>>
>>>
>>> That doesn't seem to work either.
>>>
>>> I changed the "choose" section of the <formName> part to:
>>>
>>>   <formName>
>>>    <xsl:choose>
>>>     <xsl:when test="ancestor::form/@name = '1007'">
>>>      <xsl:value-of select="ancestor::form[primary='true']/@name"/>
>>>     </xsl:when>
>>>     <xsl:otherwise>
>>>      <xsl:value-of select="ancestor::form/@name"/>
>>>     </xsl:otherwise>
>>>    </xsl:choose>
>>>   </formName>
>>>
>>> but I am still getting
>>>
>>>    <formName></formName>
>>>
>>> Tom
>>>>> "I was just guessing on this  statement and not sure how to get it to 
>>>>> work"
>>>>> You're not going to get far in XSLT like this, get a good reference 
>>>>> such as Michael Kay's latest tome from Wrox, XSLT 4th Edition.
>>>>
>>>> I will.
>>>>
>>>> I only have the O'Reilly book (Learning XSLT).
>>>>
>>>> Thanks,
>>>>
>>>> Tom
>>>>>
>>>>> -- 
>>>>>
>>>>> Joe Fawcett (MVP - XML)
>>>>> http://joe.fawcett.name
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> "tshad"  wrote in message 
>>>>> news:eByPhqB$IHA.1036@TK2MSFTNGP03.phx.gbl...
>>>>>> I can't seem to get this pattern to work:
>>>>>>
>>>>>> I have stripped down my files for testing:
>>>>>>
>>>>>> In a nutshell, what I am trying to do is this:
>>>>>>
>>>>>>     <xsl:when test="ancestor::form/@name = '1007'">
>>>>>>      <xsl:value-of select="name[ancestor::form/primary='true']"/>
>>>>>>     </xsl:when>
>>>>>>
>>>>>> If the form/@name = '1007', I want to go look at the other form tags 
>>>>>> to find the one that has an attribute primary='true' and use that 
>>>>>> name for my form name.  But I am getting a blank entry.  I was just 
>>>>>> guessing on this statement and not sure how to get it to work:
>>>>>>
>>>>>> My xslt file:
>>>>>> *****************************************************
>>>>>> <xsl:stylesheet version="1.0"
>>>>>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>>>>> 
>>>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>>>> <xsl:output method="xml" indent="yes"/>
>>>>>> <xsl:template match="/*">
>>>>>>  <xsl:copy>
>>>>>>   <xsl:apply-templates select="appraisal/data/form/tag | 
>>>>>> appraisal/data/form/section/tag">
>>>>>>    <xsl:sort select="ancestor::form/@primary" order="descending"/>
>>>>>>    <xsl:sort select="ancestor::section/@number" order="ascending" 
>>>>>> data-type="number"/>
>>>>>>   </xsl:apply-templates>
>>>>>>  </xsl:copy>
>>>>>> </xsl:template>
>>>>>> <xsl:template match="tag">
>>>>>>  <form>
>>>>>>   <sectionNumber>
>>>>>>    <xsl:value-of select="ancestor::section/@number"/>
>>>>>>   </sectionNumber>
>>>>>>   <primary>
>>>>>>    <xsl:value-of select="ancestor::form/@primary"/>
>>>>>>   </primary>
>>>>>>   <formName>
>>>>>>    <xsl:choose>
>>>>>>     <xsl:when test="ancestor::form/@name = '1007'">
>>>>>>      <xsl:value-of select="name[ancestor::form/primary='true']"/> 
>>>>>> <---------
>>>>>>     </xsl:when>
>>>>>>     <xsl:otherwise>
>>>>>>      <xsl:value-of select="ancestor::form/@name"/>
>>>>>>     </xsl:otherwise>
>>>>>>    </xsl:choose>
>>>>>>   </formName>
>>>>>>   <tagName>
>>>>>>    <xsl:value-of select="@name"/>
>>>>>>   </tagName>
>>>>>>   <flags>
>>>>>>    <xsl:if test="not(@flags)">
>>>>>>     <xsl:attribute name="xsi:nil">true</xsl:attribute>
>>>>>>    </xsl:if>
>>>>>>    <xsl:value-of select="@flags"/>
>>>>>>   </flags>
>>>>>>   <format>
>>>>>>    <xsl:if test="not(@format)">
>>>>>>     <xsl:attribute name="xsi:nil">true</xsl:attribute>
>>>>>>    </xsl:if>
>>>>>>    <xsl:value-of select="@format"/>
>>>>>>   </format>
>>>>>>   <value>
>>>>>>    <xsl:value-of select="text()"/>
>>>>>>   </value>
>>>>>>  </form>
>>>>>>  <xsl:apply-templates select="addendum[heading | body]"/>
>>>>>> </xsl:template>
>>>>>> </xsl:stylesheet>
>>>>>> ******************************************************
>>>>>>
>>>>>> My xml file:
>>>>>> ******************************************************
>>>>>> <?xml version="1.0" encoding="utf-8"?>
>>>>>> <Report>
>>>>>>  <appraisal>
>>>>>>    <data>
>>>>>>      <form name="1007" primary="false">
>>>>>>        <section type="subject" number="0">
>>>>>>          <tag name="GR_AGE.1" flags="1" format="4096">4 Yrs.</tag>
>>>>>>        </section>
>>>>>>      </form>
>>>>>>      <form name="reffee" primary="false">
>>>>>>          <tag name="FFHD_NFIP_COMMUNITY_NUMBER.1" flags="0" 
>>>>>> format="0">040040</tag>
>>>>>>      </form>
>>>>>>      <form name="1004_05" primary="true">
>>>>>>        <section type="subject" number="0">
>>>>>>          <tag name="PROP_PHYS_DEFICIENCIES_DESC.1" flags="4" 
>>>>>> format="4096">None apparent </tag>
>>>>>>        </section>
>>>>>>      </form>
>>>>>>    </data>
>>>>>>  </appraisal>
>>>>>> </Report>
>>>>>> ********************************************************
>>>>>>
>>>>>> My result:
>>>>>> ******************************************************
>>>>>> <?xml version="1.0" encoding="utf-8"?>
>>>>>> <Report>
>>>>>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>>>>    <sectionNumber>0</sectionNumber>
>>>>>>    <primary>true</primary>
>>>>>>    <formName>1004_05</formName>
>>>>>>    <tagName>PROP_PHYS_DEFICIENCIES_DESC.1</tagName>
>>>>>>    <flags>4</flags>
>>>>>>    <format>4096</format>
>>>>>>    <value>None apparent </value>
>>>>>>  </form>
>>>>>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>>>>    <sectionNumber></sectionNumber>
>>>>>>    <primary>false</primary>
>>>>>>    <formName>reffee</formName>
>>>>>>    <tagName>FFHD_NFIP_COMMUNITY_NUMBER.1</tagName>
>>>>>>    <flags>0</flags>
>>>>>>    <format>0</format>
>>>>>>    <value>040040</value>
>>>>>>  </form>
>>>>>>  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>>>>    <sectionNumber>0</sectionNumber>
>>>>>>    <primary>false</primary>
>>>>>>    <formName></formName>                      <-------- Want this to 
>>>>>> be 1004_05
>>>>>>    <tagName>GR_AGE.1</tagName>
>>>>>>    <flags>1</flags>
>>>>>>    <format>4096</format>
>>>>>>    <value>4 Yrs.</value>
>>>>>>  </form>
>>>>>> </Report>
>>>>>> *******************************************************
>>>>>>
>>>>>> Everything else works fine.
>>>>>>
>>>>>> What should that line be?  Do I need to do another match and 
>>>>>> template?
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Tom
>>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
date: Wed, 13 Aug 2008 08:55:53 +0100   author:   Joe Fawcett am

Re: Pattern problem   
tshad wrote:

> ancestor::form/@name gives me 1007, as it should.  But I need to look at all 
> the forms on the same level and get the one that has @primary = 'true' and 
> use the @name of that form.
> 
> Is this the wrong way to get that?
> 
> Seems pretty straight forward.
> 
> I assume the pattern in:
> 
> <xsl:value-of select="ancestor::form[@primary='true']/@name"/>
> 
> says to look for all the ancestor "form" tags and look at the one that one. 
> I did notice that I had primary set in my program without the "@".  But even 
> after changing it to the above is not working.

The sample XML you posted looks like this:

<Report>
   <appraisal>
     <data>
       <form name="1007" primary="false">
         <section type="subject" number="0">
           <tag name="GR_AGE.1" flags="1" format="4096">4 Yrs.</tag>
         </section>
       </form>
       <form name="reffee" primary="false">
           <tag name="FFHD_NFIP_COMMUNITY_NUMBER.1" flags="0"
format="0">040040</tag>
       </form>
       <form name="1004_05" primary="true">
         <section type="subject" number="0">
           <tag name="PROP_PHYS_DEFICIENCIES_DESC.1" flags="4"
format="4096">None apparent </tag>
         </section>
       </form>
     </data>
   </appraisal>
</Report>

In that sample each 'tag' element has just one ancestor element of the 
name 'form'. However each such 'form' element has siblings so perhaps 
you want
  <xsl:value-of select="(
   ancestor::form[@primary = 'true'] |
   ancestor::form/preceding-sibling::form[@primary = 'true'] |
   ancestor::form/following-sibling::form[@primary = 'true']
   )[1]/@name"/>
which looks at the sibling 'form' elements as well.

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Wed, 13 Aug 2008 15:17:45 +0200   author:   Martin Honnen

Re: Pattern problem   
"Martin Honnen"  wrote in message 
news:eXhB7bU$IHA.2060@TK2MSFTNGP05.phx.gbl...
> tshad wrote:
>
>> ancestor::form/@name gives me 1007, as it should.  But I need to look at 
>> all the forms on the same level and get the one that has @primary = 
>> 'true' and use the @name of that form.
>>
>> Is this the wrong way to get that?
>>
>> Seems pretty straight forward.
>>
>> I assume the pattern in:
>>
>> <xsl:value-of select="ancestor::form[@primary='true']/@name"/>
>>
>> says to look for all the ancestor "form" tags and look at the one that 
>> one. I did notice that I had primary set in my program without the "@". 
>> But even after changing it to the above is not working.
>
> The sample XML you posted looks like this:
>
> <Report>
>   <appraisal>
>     <data>
>       <form name="1007" primary="false">
>         <section type="subject" number="0">
>           <tag name="GR_AGE.1" flags="1" format="4096">4 Yrs.</tag>
>         </section>
>       </form>
>       <form name="reffee" primary="false">
>           <tag name="FFHD_NFIP_COMMUNITY_NUMBER.1" flags="0"
> format="0">040040</tag>
>       </form>
>       <form name="1004_05" primary="true">
>         <section type="subject" number="0">
>           <tag name="PROP_PHYS_DEFICIENCIES_DESC.1" flags="4"
> format="4096">None apparent </tag>
>         </section>
>       </form>
>     </data>
>   </appraisal>
> </Report>
>
> In that sample each 'tag' element has just one ancestor element of the 
> name 'form'. However each such 'form' element has siblings so perhaps you 
> want
>  <xsl:value-of select="(
>   ancestor::form[@primary = 'true'] |
>   ancestor::form/preceding-sibling::form[@primary = 'true'] |
>   ancestor::form/following-sibling::form[@primary = 'true']
>   )[1]/@name"/>
> which looks at the sibling 'form' elements as well.
>
That worked perfectly.

Just a couple of questions.

Since I know that 1007 is not a primary form (as there is only one primary 
form), I assume I could just do:

<xsl:value-of select="(
   ancestor::form/preceding-sibling::form[@primary = 'true'] |
   ancestor::form/following-sibling::form[@primary = 'true']
   )[1]/@name"/>

Does ancestor::form look only at the direct ancesters - which is why it 
didn't find the siblings of the ancestor?

In ancestor::form/preceding-sibling::form, does it say:

Look at the ancestor named form then look at all the siblings named form 
that came before it (and the reverse for following-sibling)?

What does the [1] do?  Is this in case it passes back more than one result?

If there is only one result, do I need the [1]?

Thanks,

Tom
> -- 
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
date: Wed, 13 Aug 2008 09:08:20 -0700   author:   tshad

Re: Pattern problem   
tshad wrote:

>> <Report>
>>   <appraisal>
>>     <data>
>>       <form name="1007" primary="false">
>>         <section type="subject" number="0">
>>           <tag name="GR_AGE.1" flags="1" format="4096">4 Yrs.</tag>
>>         </section>
>>       </form>
>>       <form name="reffee" primary="false">
>>           <tag name="FFHD_NFIP_COMMUNITY_NUMBER.1" flags="0"
>> format="0">040040</tag>
>>       </form>
>>       <form name="1004_05" primary="true">
>>         <section type="subject" number="0">
>>           <tag name="PROP_PHYS_DEFICIENCIES_DESC.1" flags="4"
>> format="4096">None apparent </tag>
>>         </section>
>>       </form>
>>     </data>
>>   </appraisal>
>> </Report>
>>


> Just a couple of questions.
> 
> Since I know that 1007 is not a primary form (as there is only one primary 
> form), I assume I could just do:
> 
> <xsl:value-of select="(
>    ancestor::form/preceding-sibling::form[@primary = 'true'] |
>    ancestor::form/following-sibling::form[@primary = 'true']
>    )[1]/@name"/>

I have not looked in detail at your stylesheet, whether the above will 
do the same depends on the 'tag' element you apply it on.


> Does ancestor::form look only at the direct ancesters - which is why it 
> didn't find the siblings of the ancestor?

The ancerstor axis includes all ancestor nodes so for instance for the
   <tag name="GR_AGE.1" flags="1" format="4096">4 Yrs.</tag>
in the sample cited above these are a 'section' element, a 'form' 
element, a 'data' element, an 'appraisal' element, an 'Report' element, 
and the document node. ancestor::form then only the selects the 'form' 
element nodes on the axis which in that example is a single 'form' element.

> In ancestor::form/preceding-sibling::form, does it say:
> 
> Look at the ancestor named form then look at all the siblings named form 
> that came before it (and the reverse for following-sibling)?

Yes.

> What does the [1] do?  Is this in case it passes back more than one result?

It explictly selects the first of that union my sample selects.

> If there is only one result, do I need the [1]?

With xsl:value-of in XSLT 1.0 you do not need the [1], even if there are 
several elements found. I put it in because I did not know whether the 
XPath might find several 'form' elements and wanted to make it clear 
that only one should be selected for output.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Wed, 13 Aug 2008 18:51:38 +0200   author:   Martin Honnen

Re: Pattern problem   
"Martin Honnen"  wrote in message 
news:O4eIcTW$IHA.1452@TK2MSFTNGP02.phx.gbl...
> tshad wrote:
>
>>> <Report>
>>>   <appraisal>
>>>     <data>
>>>       <form name="1007" primary="false">
>>>         <section type="subject" number="0">
>>>           <tag name="GR_AGE.1" flags="1" format="4096">4 Yrs.</tag>
>>>         </section>
>>>       </form>
>>>       <form name="reffee" primary="false">
>>>           <tag name="FFHD_NFIP_COMMUNITY_NUMBER.1" flags="0"
>>> format="0">040040</tag>
>>>       </form>
>>>       <form name="1004_05" primary="true">
>>>         <section type="subject" number="0">
>>>           <tag name="PROP_PHYS_DEFICIENCIES_DESC.1" flags="4"
>>> format="4096">None apparent </tag>
>>>         </section>
>>>       </form>
>>>     </data>
>>>   </appraisal>
>>> </Report>
>>>
>
>
>> Just a couple of questions.
>>
>> Since I know that 1007 is not a primary form (as there is only one 
>> primary form), I assume I could just do:
>>
>> <xsl:value-of select="(
>>    ancestor::form/preceding-sibling::form[@primary = 'true'] |
>>    ancestor::form/following-sibling::form[@primary = 'true']
>>    )[1]/@name"/>
>
> I have not looked in detail at your stylesheet, whether the above will do 
> the same depends on the 'tag' element you apply it on.
>
>
>> Does ancestor::form look only at the direct ancesters - which is why it 
>> didn't find the siblings of the ancestor?
>
> The ancerstor axis includes all ancestor nodes so for instance for the
>   <tag name="GR_AGE.1" flags="1" format="4096">4 Yrs.</tag>
> in the sample cited above these are a 'section' element, a 'form' element, 
> a 'data' element, an 'appraisal' element, an 'Report' element, and the 
> document node. ancestor::form then only the selects the 'form' element 
> nodes on the axis which in that example is a single 'form' element.
>
>> In ancestor::form/preceding-sibling::form, does it say:
>>
>> Look at the ancestor named form then look at all the siblings named form 
>> that came before it (and the reverse for following-sibling)?
>
> Yes.
>
>> What does the [1] do?  Is this in case it passes back more than one 
>> result?
>
> It explictly selects the first of that union my sample selects.
>
>> If there is only one result, do I need the [1]?
>
> With xsl:value-of in XSLT 1.0 you do not need the [1], even if there are 
> several elements found. I put it in because I did not know whether the 
> XPath might find several 'form' elements and wanted to make it clear that 
> only one should be selected for output.
>
I decided to keep it in myself to remind myself that there could be a set 
and not just one result.

That explains a lot.

Thanks,

Tom
>
> -- 
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
date: Wed, 13 Aug 2008 10:10:10 -0700   author:   tshad

Google
 
Web ureader.com


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