Textpattern CMS support forum

You are not logged in. Register | Login | Help

#311 2018-12-10 00:09:02

lazlo
Member
Registered: 2004-02-24
Posts: 102

Re: etc_query: all things Textpattern

Hi Oleg

I recently came across xpath and have been trying to get my head around it I am hoping for guidance with using it with etc_query.

I have a custom field called “ONIX_record” that contains a single XML record in a block code below.
I have been playing around with xpath at the XPath Expression Testbed which seems understandable but I am having trouble translating it to etc_query.

I want to display the text inside: <PersonNameInverted>Homel, David</PersonNameInverted>

This code highlights the node in the test bed but how do I translate this to etc_query?

//Product/Contributor[ContributorRole='B06']/PersonNameInverted

And the biggie (for me) is how do I search for across my database for multiple matches?

An example of what I want to do is display an alpha list of all my Contributors, similar to what I had done before previously with your help.
see here:

lazlo wrote #298483:

Hey Oleg

Hoping you can help me out again as the <!— alpha list A-Z —> works wonderfully for the “Title” field. In my case I use it for both an Book Title List and an Author List. These articles have alternative titles that exist in a custom field, in one case it is <txp:custom_field name=“Contributor_Full_Name_Reversed” />

the xml code

<xml><Product>
    <RecordReference>9780889227729</RecordReference>
    <NotificationType>03</NotificationType>
    <ProductIdentifier>
      <ProductIDType>03</ProductIDType>
      <IDValue>9780889227729</IDValue>
    </ProductIdentifier>
    <ProductIdentifier>
      <ProductIDType>15</ProductIDType>
      <IDValue>9780889227729</IDValue>
    </ProductIdentifier>
    <ProductIdentifier>
      <ProductIDType>02</ProductIDType>
      <IDValue>0889227721</IDValue>
    </ProductIdentifier>
    <ProductIdentifier>
      <ProductIDType>01</ProductIDType>
      <IDTypeName>ONIX_NOSEQ</IDTypeName>
      <IDValue>b99c6a66-b284-4882-842b-2bbf85c57a9b</IDValue>
    </ProductIdentifier>
    <Barcode>00</Barcode>
    <Barcode>00</Barcode>
    <ProductForm>DG</ProductForm>
    <ProductFormDetail>B102</ProductFormDetail>
    <EpubType>099</EpubType>
    <NoSeries></NoSeries>
    <Title>
      <TitleType>01</TitleType>
      <TitleText>A Covenant of Salt</TitleText>
      <TitlePrefix>A</TitlePrefix>
      <TitleWithoutPrefix>Covenant of Salt</TitleWithoutPrefix>
    </Title>
    <WorkIdentifier>
      <WorkIDType>15</WorkIDType>
      <IDValue>9780889225664</IDValue>
    </WorkIdentifier>
    <Contributor>
      <SequenceNumber>1</SequenceNumber>
      <ContributorRole>A01</ContributorRole>
      <PersonName>Martine Desjardins</PersonName>
      <PersonNameInverted>Desjardins, Martine</PersonNameInverted>
      <NamesBeforeKey>Martine</NamesBeforeKey>
      <KeyNames>Desjardins</KeyNames>
    </Contributor>
    <Contributor>
      <SequenceNumber>2</SequenceNumber>
      <ContributorRole>B06</ContributorRole>
      <PersonName>David Homel</PersonName>
      <PersonNameInverted>Homel, David</PersonNameInverted>
      <NamesBeforeKey>David</NamesBeforeKey>
      <KeyNames>Homel</KeyNames>
    </Contributor>
    <Contributor>
      <SequenceNumber>3</SequenceNumber>
      <ContributorRole>B06</ContributorRole>
      <PersonName>Fred A. Reed</PersonName>
      <PersonNameInverted>Reed, Fred A.</PersonNameInverted>
      <NamesBeforeKey>Fred A.</NamesBeforeKey>
      <KeyNames>Reed</KeyNames>
    </Contributor>
    <NoEdition></NoEdition>
    <Language>
      <LanguageRole>01</LanguageRole>
      <LanguageCode>eng</LanguageCode>
    </Language>
    <NumberOfPages>160</NumberOfPages>
    <MainSubject>
      <MainSubjectSchemeIdentifier>10</MainSubjectSchemeIdentifier>
      <SubjectCode>FIC019000</SubjectCode>
      <SubjectHeadingText>FICTION / Literary</SubjectHeadingText>
    </MainSubject>
    <Audience>
      <AudienceCodeType>01</AudienceCodeType>
      <AudienceCodeValue>01</AudienceCodeValue>
    </Audience>
      <OtherText>
      <TextTypeCode>02</TextTypeCode>
      <TextFormat>05</TextFormat>
      <Text>&lt;p&gt;This novel explores the snares of individual and collective memory as they are used to justify and preserve ancestral grudges.&lt;/p&gt;</Text>
      <TextPublicationDate>20130403</TextPublicationDate>
    </OtherText>
    <OtherText>
      <TextTypeCode>05</TextTypeCode>
      <TextFormat>05</TextFormat>
      <Text>“Mining from the past, Desjardins extracts treasures without \\\'getting caught,\\\' and surfaces like a breath of fresh air. &lt;em&gt;A Covenant of Salt&lt;/em&gt; marries literary traditions in a sleek gothic ceremony, silvery salt sprinkled like confetti and the Saint Lawrence coursing through.&lt;br /&gt;— &lt;em&gt;Montreal Review of Books&lt;/em&gt;</Text>
      <TextPublicationDate>20130403</TextPublicationDate>
    </OtherText>
    <MediaFile>
      <MediaFileTypeCode>04</MediaFileTypeCode>
      <MediaFileFormatCode>03</MediaFileFormatCode>
      <MediaFileLinkTypeCode>01</MediaFileLinkTypeCode>
      <MediaFileLink>http://talonbooks.com/images/9780889225664.jpg</MediaFileLink>
      <MediaFileDate>20160229</MediaFileDate>
    </MediaFile>
    <Imprint>
      <NameCodeType>06</NameCodeType>
      <NameCodeValue>9780889227729</NameCodeValue>
      <ImprintName>Talonbooks</ImprintName>
    </Imprint>
    <Publisher>
      <PublishingRole>01</PublishingRole>
      <PublisherName>Talonbooks</PublisherName>
    </Publisher>
    <CityOfPublication>Vancouver</CityOfPublication>
    <CountryOfPublication>CA</CountryOfPublication>
    <PublishingStatus>04</PublishingStatus>
    <PublicationDate>20130901</PublicationDate>
    <YearFirstPublished>2013</YearFirstPublished>
    <SalesRights>
      <SalesRightsType>01</SalesRightsType>
      <RightsTerritory>WORLD</RightsTerritory>
    </SalesRights>
    <RelatedProduct>
      <RelationCode>13</RelationCode>
      <ProductIdentifier>
        <ProductIDType>15</ProductIDType>
        <IDValue>9780889225664</IDValue>
      </ProductIdentifier>
      <ProductForm>BC</ProductForm>
      <ProductFormDetail>B106</ProductFormDetail>
    </RelatedProduct>
    <SupplyDetail>
      <SupplierName>Constellation</SupplierName>
      <SupplierRole>01</SupplierRole>
      <ReturnsCodeType>02</ReturnsCodeType>
      <ReturnsCode>N</ReturnsCode>
      <ProductAvailability>20</ProductAvailability>
      <OnSaleDate>20130901</OnSaleDate>
      <Price>
        <PriceTypeCode>01</PriceTypeCode>
        <ClassOfTrade>Electronic Book Text</ClassOfTrade>
        <PriceAmount>17.95</PriceAmount>
        <CurrencyCode>CAD</CurrencyCode>
      </Price>
    </SupplyDetail>
  </Product></xml>

Last edited by lazlo (2018-12-10 00:18:10)

Offline

#312 2018-12-10 10:10:44

etc
Developer
Registered: 2010-11-11
Posts: 3,157
Website

Re: etc_query: all things Textpattern

Hi Les,

your xpath looks ok, you just need to pass markup="xml" to etc_query:

<txp:etc_query data='<txp:custom_field name="ONIX_record" escape="" />'
    query="//Product/Contributor[ContributorRole='B06']/PersonNameInverted"
    markup="xml" wraptag="ul" break="li"
>
    Contributor: {?}
</txp:etc_query>

Constructing alpha lists is more complicated, since your custom fields can contain multiple contributors, so sorting at db level is problematic. I think you can extract all records and sort them via XSL, like here, but haven’t tried yet.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#313 2018-12-10 10:37:40

etc
Developer
Registered: 2010-11-11
Posts: 3,157
Website

Re: etc_query: all things Textpattern

Here is something to make you start:

<txp:variable name="contlist">
<txp:article_custom wraptag="ul">
<txp:etc_query data='<txp:custom_field name="ONIX_record" escape="" />'
    query="//Product/Contributor[ContributorRole='B06']/PersonNameInverted"
    markup="xml" break="li"
>{?}</txp:etc_query>
</txp:article_custom>
</txp:variable>

<txp:etc_query data='<txp:variable name="contlist" />'>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" />
<xsl:template match="ul">
	<dl>
	<xsl:for-each select="li">
		<xsl:sort select="." order="ascending" />
		<txp:if_different><dt><strong><xsl:copy-of select="substring(text(), 1, 1)" /></strong></dt></txp:if_different>
		<dd><xsl:copy-of select="text()" /></dd>
	</xsl:for-each>
	</dl>
</xsl:template>
</xsl:stylesheet>
</txp:etc_query>

etc_[ query | search | pagination | date | tree | cache ]

Offline

#314 2019-03-18 15:01:43

singaz
Member
Registered: 2017-03-12
Posts: 67

Re: etc_query: all things Textpattern

After every 3 paragraphs I add my phrase. Now I use this:

<txp:etc_query data='<txp:body />' separator="|\/|" replace='p[2]$=<txp:output_form form="remark_1" />|\/| p[4]$=<txp:output_form form="remark_2/>"/> |\/| p[8]$=<txp:output_form form="remark_3"/>' />

I want to complicate the task. It is necessary to add a phrase to the article for the section and for the category.

Separately, such a request works:

<txp:output_form form='remark_1-<txp:section/><txp:category/>' />

<txp:output_form form='remark_2-<txp:section/><txp:category/>' />

<txp:output_form form='remark_3-<txp:section/><txp:category/>' />

But etc_query doesn’t work:

<txp:etc_query data='<txp:body />' separator="|\/|" replace='p[2]$=<txp:output_form form='remark_1-<txp:section/><txp:category/>' />|\/| p[6]$=<txp:output_form form='remark_2-<txp:section/><txp:category/>'/> |\/| p[10]$=<txp:output_form form='remark_3-<txp:section/><txp:category/>' />' />

I do not understand how to do it right.

How can I add a category and / or section?


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

#315 2019-03-18 15:24:17

etc
Developer
Registered: 2010-11-11
Posts: 3,157
Website

Re: etc_query: all things Textpattern

Hello,

you should duplicate quotes inside quotes:

<txp:etc_query data='<txp:body />' separator="|\/|"
    replace='p[2]$=<txp:output_form form=''remark_1-<txp:section/><txp:category/>'' />|\/|
        p[6]$=<txp:output_form form=''remark_2-<txp:section/><txp:category/>''/> |\/|
        p[10]$=<txp:output_form form=''remark_3-<txp:section/><txp:category/>'' />' />

Hope that helps.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#316 2019-03-18 16:13:40

singaz
Member
Registered: 2017-03-12
Posts: 67

Re: etc_query: all things Textpattern

I checked. It is working.

Thank you, Oleg!


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

#317 2019-03-18 16:20:47

singaz
Member
Registered: 2017-03-12
Posts: 67

Re: etc_query: all things Textpattern

P.S.

Question out of curiosity.

How to write this in a container?

<txp:etc_query>
....
</txp:etc_query>

I can not do it


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

#318 2019-03-18 18:42:05

etc
Developer
Registered: 2010-11-11
Posts: 3,157
Website

Re: etc_query: all things Textpattern

singaz wrote #317140:

How to write this in a container?

You can rename your forms to remark_2-... (6, 10, …), and try something like

<txp:etc_query data='<txp:body />' query="*">
    {.}
    <txp:evaluate query="{#row}=2 or {#row}=6 or {#row}=10">
        <txp:output_form form='remark_{#row}-<txp:section /><txp:category />' />
    </txp:evaluate>
</txp:etc_query>

This will insert the forms after the 2nd, 6th and 10 HTML node, not necessary p. The body must be well structured.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#319 2019-03-19 10:33:06

singaz
Member
Registered: 2017-03-12
Posts: 67

Re: etc_query: all things Textpattern

Plugin contains great features. Need to learn to work with them. I try.

Thank you!


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

Board footer

Powered by FluxBB